I must be doing something very silly, but even after a whole day, I cant call onActivityResult
on MainActivity
from another activity.
In my AuxActivity, I have
adapter.setOnItemClickListener(new CityListAdapter.ClickListener() {
@Override
public void onItemClick(View v, int position) {
City city =adapter.getCityAtPosition(position);
// Toast.makeText(getApplicationContext(),
// city.getCity()+"\n"+city.getLatitude()+"\n"+city.getLongitude(),
// Toast.LENGTH_LONG).show();
Double Lat = city.getLatitude();
Double Long = city.getLongitude();
Intent mainIntent = new Intent(getApplicationContext(), MainActivity.class);
mainIntent.putExtra("Lat", Lat);
mainIntent.putExtra("Long", Long);
mainIntent.putExtra("DbResultCode", Db_ACTIVITY_REQUEST_CODE);
startActivityForResult(mainIntent, Db_ACTIVITY_REQUEST_CODE);
finish();
}
});
In MainActivity
, I am doing
// Inside onCreate
// Check Intent from Db
Intent intent = getIntent();
if (intent != null) {
Lat = intent.getDoubleExtra("Lat", 0.0);
Long = intent.getDoubleExtra("Long", 0.0);
DbResultStat = intent.getIntExtra("DbResultCode", 0);
}
I am getting values of Lat
and Long
properly here. But, then,
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Toast.makeText(this, ""+requestCode, Toast.LENGTH_LONG).show();
if (requestCode == DbActivity.Db_ACTIVITY_REQUEST_CODE){
if (resultCode==RESULT_OK){
setupViewPager();
}
}
This part is never called. I am still learning android, using the codelabs
. So, anything new is giving me a lot of headache.
What I am doing wrong here?