First Activity
namespace TrackView.Screens
{
[Activity(Label = "MainActivity", Theme = "@style/AppTheme.NoActionBar")]
public class MainActivity : AppCompatActivity
{
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
// Set our view from the "main" layout resource
SetContentView(Resource.Layout.Main);
Button btn = FindViewById<Button>(Resource.Id.button1);
btn.Text = "First";
btn.Click += Btn_Click;
}
private void Btn_Click(object sender, System.EventArgs e)
{
var intent = new Intent(this, typeof(SecondActivity));
StartActivityForResult(intent, 2);
}
protected override void OnActivityResult(int requestCode, [GeneratedEnum] Result resultCode, Intent data)
{
base.OnActivityResult(requestCode, resultCode, data);
if (requestCode == 2)
{
if (resultCode == Result.Ok)
{
string isd = data.GetStringExtra("MESSAGE");
Toast.MakeText(this, isd.ToString(), ToastLength.Long).Show();
}
}
}
}
}
Second Activity
namespace TrackView.Screens
{
[Activity( Theme = "@style/AppTheme.NoActionBar")]
public class CountryList : AppCompatActivity
{
ListView listView;
CountryListAdapter listAdapter;
List<TrackViewShared.Model.Country> cList;
private Android.Support.V7.Widget.Toolbar mToolbar;
private EditText edtSeach;
static TrackViewServiceManager trackViewServiceMgr;
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
SetContentView(Resource.Layout.country_list_layout);
mToolbar = (Android.Support.V7.Widget.Toolbar)FindViewById(Resource.Id.toolbar_country);
SetSupportActionBar(mToolbar);
Android.Support.V7.App.ActionBar action = this.SupportActionBar;
action.SetDisplayShowCustomEnabled(true);
action.SetCustomView(Resource.Layout.search_bar_country);//add the custom view
action.SetDisplayShowTitleEnabled(false); //hide the title
edtSeach = (EditText)action.CustomView.FindViewById(Resource.Id.edtSearch); //the text editor
edtSeach.TextChanged += EdtSeach_TextChanged;
listView = FindViewById<ListView>(Resource.Id.lvCList);
trackViewServiceMgr = new TrackViewServiceManager(new TrackViewRestService());
listView.SetScrollContainer(true);
listView.ItemClick += ListView_ItemClick;
//RunOnUiThread(PopulateListView);
PopulateListView();
// PopulateListView();
}
private void EdtSeach_TextChanged(object sender, Android.Text.TextChangedEventArgs e)
{
List<Country> cl = cList.Where(c => c.countryName.Contains(edtSeach.Text)).ToList<Country>();
var filterdAdatper = new CountryListAdapter(this, cl);
listView.Adapter = filterdAdatper;
}
private async void PopulateListView()
{
cList = await trackViewServiceMgr.GetCountryList("en", "1");
listAdapter = new CountryListAdapter(this, cList);
listView.Adapter = listAdapter;
}
private void SendToJoin(string isd)
{
Intent intent = new Intent();
intent.PutExtra("MESSAGE", isd);
intent.AddFlags(ActivityFlags.ClearTop);
SetResult(Android.App.Result.Ok, intent);
this.Finish();//finishing activity
}
private void ListView_ItemClick(object sender, AdapterView.ItemClickEventArgs e)
{
//itemClicked = true;
string message = ObjectTypeHelper.Cast<Country>(listView.GetItemAtPosition(e.Position)).countryId.ToString();
//Intent intent = new Intent(this,typeof())
//intent.PutExtra("MESSAGE", message);
// intent.AddFlags(ActivityFlags.ClearTop );
//
// Intent intent = new Intent(this, typeof(JoinScreen));
Intent intent = new Intent();
intent.PutExtra("MESSAGE", message);
intent.AddFlags(ActivityFlags.ClearTop);
SetResult(Android.App.Result.Ok, intent);
this.Finish();
}
}
My purpose is this: while clicking on the "ISD" edit box in activity 1, a second activity containing a list of countries will be displayed from which the user will select a country and after that the first activity will get the country code. In activity second, I have used async calls to list of countries from the RESETful webservice. But here the problem is after finishing the Activity2, Activity 1 never displayed to show the ISD code ( that means, StartActivityForResult seems to be not working properly as intended.. While debugging its found that, OnCreate method of Activity2 is called again after finishing it.. 1 Day passed, but I didnt get a solution.. Please help