I launched Activity B via deep link and I'm expecting Activity A to be launched on Up Button click.
Here's my manifest
<activity
android:name=".ui.activity.B"
android:label="@string/title_activity_search"
android:parentActivityName=".ui.activity.A" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".ui.activity.A"/>
...
<!-- deep link -->
...
</activity>
B Activity code is here.
public class B extends AppCompatActivity {
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Toolbar vToolbar = ((Toolbar) findViewById(R.id.toolbar));
setSupportActionBar(vToolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
// Respond to the action bar's Up/Home button
case android.R.id.home:
NavUtils.navigateUpFromSameTask(this);
return true;
}
return super.onOptionsItemSelected(item);
}
}
You can copy/past this code and it works if Activity B extends FragmentActivity. But I need this to be working with AppCompatActivity. What am I doing wrong?
You're opening your
Activityfrom another application. So there is no otherActivityavailable in the stack. Thus you should not get the parentActivityto come up in the front when you press the up button. If the target parent activity is in the task's back stack, it is brought forward. From the developers documentation.So in your case you need to do something like this stated in the documentation.