I have two activities
MainActivity
DeepLinkActivity
I set up everything to use the NavUtils
for navi
It doesn't work for me too. So I handle up this way:
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == android.R.id.home) {
Intent intent = new Intent(this, MainActivity.class);
startActivity(intent);
finish();
return true;
}
return super.onOptionsItemSelected(item);
}
My MainActivity is marked as singleTask in android manifest
android:launchMode="singleTask"
Try this :
@Override
public boolean onOptionsItemSelected(final MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
Intent upIntent = NavUtils.getParentActivityIntent(this);
if (NavUtils.shouldUpRecreateTask(this, upIntent)) {
// create new task
TaskStackBuilder.create(this).addNextIntentWithParentStack(upIntent)
.startActivities();
} else {
// Stay in same task
NavUtils.navigateUpTo(this, upIntent);
}
break;
default:
return super.onOptionsItemSelected(item);
}
return true;
}
I think that method is bugged. I've read support library source code, and that method check for intent's action. It only works when your App was previously created..as you've described, if you kill it from Apps preview, shouldUp method stops working.
I've fixed this using my own "shouldUpRecreateTask". When I receive a Notification that creates directly an Activity (Like your behaviour), I send from my BroadCastReceiver a custom Action inside the intent. Then, in my Method I do the next thing:
private final boolean shouldUpRecreateTask(Activity from){
String action = from.getIntent().getAction();
return action != null && action.equals(com.xxxxxx.activities.Intent.FROM_NOTIFICATION);
}
..........................
if (shouldUpRecreateTask(this)) {
TaskStackBuilder.create(this)
.addNextIntentWithParentStack(upIntent)
.startActivities();
} else {
fillUpIntentWithExtras(upIntent);
NavUtils.navigateUpTo(this, upIntent);
}