I have two activities. Say Activity A
and Activity B
.
From Activity A
I click a button to launch Activity B
This is the code I use for this:
Intent intent = new Intent(this, ActivityB.class);
this.startActivity(intent);
Now at this point, I am in
Activity B
. On the on create method of Activity B
, I enable the up button.
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_view_news);
getActionBar().setDisplayHomeAsUpEnabled(true); //Here//
}
and on the event handle for the "up" button, i have this code:
public boolean onOptionsItemSelected(MenuItem item){
switch (item.getItemId()) {
case android.R.id.home:
finish();
NavUtils.navigateUpFromSameTask(this);
default:
return super.onOptionsItemSelected(item);
}
}
Now I decide to go back to
Activity A
I click the up button in the action bar which looks like this: 
Now the problem is, when I click the "up button", it goes back to Activity A
which is fine, but it restarts it. How can make it stop restarting? I just want it to resume.
When I use my hardware back button, it works as expected. i.e it goes to Activity A
and resumes it instead of restarting it.
I want my activity to resume because on that activity, I download some string online and so I don't want it to keep re downloading the data when a users goes from Activity B -> Activity A
Edit My manifest file for
Activity B
section looks like this:
<activity
android:name="com.example.android.ActivityB"
android:label="@string/title_activity_view_news"
android:parentActivityName="com.example.android.ActivityA">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.example.android.ActivityA" />
</activity>
Edit 2 [Answer] Ok so, this was pretty unexpected but in my AndroidManifest.xml, in the Activity A section, I had to add the following line liner.
android:launchMode="singleTop"
so it now looks like this:
<activity
android:name="com.example.android.ActivityA"
android:label="@string/app_name"
android:launchMode="singleTop"> //**HERE**//
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>