No additional functionality in Activity.getIntent () when returning to it from a child.

I have an Activity A that I am starting with some additional functionality (for example, put some data in an intent that starts the Activity). From this activity, I launch another activity B. The problem is that when I return from B to A by calling finish (), Activity's getIntent () method returns an Intent that does not contain any additional functionality. So my questions are: is this normal behavior? And is there a way that I can signal Activity A that I want it to retain the Intent it was started from. Oh, and please note that I have overridden onSaveInstanceState () in Activity A.

EDIT: I no longer experience this kind of behavior on my device. And I haven't changed anything in the code. I am using a 3 year old device for testing. I wonder if this could have been caused by a crash on the device?

+3


source to share


3 answers


I understood. This problem occurs when I click on the back arrow of the ActionBar, not when I click the back button of the device. Because when the Back button is clicked, the Object Handler () method is called and the application usually reverts to the already created Activity A instance, when by clicking the back arrow of the ActionBar, by default, Activity B does not call finish (), instead it creates a new instance of Activity A due to android side navigation functionality. So the solution was to override the functionality of the ActionBar arrow button like this (method added to Activity B):



@Override
public boolean onOptionsItemSelected(MenuItem menuItem) {
    int itemId = menuItem.getItemId();
    if (itemId == android.R.id.home) {
        onBackPressed();
        return true;
    }
    return super.onOptionsItemSelected(menuItem);
}

      

+3


source


Is this normal behavior?



Yes it is. Start B with startActivityForResult

and override in onActivityResult

. Before you end up calling B setResult(int, intent)

, populating the intent with the data you want to return to A. onActivityResult

get the same intent as the third parameter.

+1


source


Yes Behavior is normal. If you want to start Activity X from Activity Y and get some data from X and return to Y, you must use the startActivityForResult(intent,request_code) Then you need to override the

onActivityResult () method `In activity X, after creating the intent and entering data into the intent, you need to do the following

setResult (RESUKT_OK, i);

`

+1


source







All Articles