xamarin.android - Why Data Can not Pass to Second Activity -
using xamarinstudio , below code base on sample in tutorial. here questions.
- do need generate androidmanifest project option> android application when testing app ?
why there no data passing on have generated androidmanifest , code :
---activity 1 [activity (label = "hellomultiscreen", mainlauncher = true,icon = "@drawable/icon")] public class firstactivity : activity { int count = 1; protected override void oncreate (bundle bundle) { base.oncreate (bundle); //use ui created in main.axml setcontentview (resource.layout.main); var showsecond = findviewbyid (resource.id.showsecond); showsecond.click += (sender, e) => { var second = new intent(this, typeof(secondactivity)); second.putextra("firstdata", "data firstactivity"); startactivity (typeof(secondactivity)); }; } } ---activity 2 [activity (label = "secondactivity")] public class secondactivity : activity { protected override void oncreate (bundle bundle) { base.oncreate (bundle); // create application here setcontentview (resource.layout.second); var label = findviewbyid (resource.id.screen2label); label.text = intent.getstringextra("firstdata") ?? "data not available"; } } thanks
ok found problem when remade project myself. problem lies in piece of code:
var second = new intent(this, typeof(secondactivity)); second.putextra("firstdata", "data firstactivity"); startactivity (typeof(secondactivity)); what happens make intent right data. start new activity without data. fix change code this:
var second = new intent(this, typeof(secondactivity)); second.putextra("firstdata", "data firstactivity"); startactivity(second);`
Comments
Post a Comment