Skip to content

Instantly share code, notes, and snippets.

@nein37
Created August 16, 2014 09:51
Show Gist options
  • Save nein37/121b3ccd3d9248d03a6a to your computer and use it in GitHub Desktop.
Save nein37/121b3ccd3d9248d03a6a to your computer and use it in GitHub Desktop.
Upボタンの実装メモ ref: http://qiita.com/nein37/items/6a063f5462400036920b
<activity
android:name=".ChildActivity"
android:launchMode="singleTop"
android:parentActivityName=".ParentActivity">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".ParentActivity" />
</activity>
java.lang.IllegalArgumentException: Activity ACTIVITY_NAME does not have a parent activity name specified. (Did you forget to add the android.support.PARENT_ACTIVITY <meta-data> element in your manifest?)
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
NavUtils.navigateUpFromSameTask(this);
return true;
}
return super.onOptionsItemSelected(item);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
Intent upIntent = NavUtils.getParentActivityIntent(this);
if (NavUtils.shouldUpRecreateTask(this, upIntent)) {
// 新しくタスクを生成する必要がある
TaskStackBuilder.create(this)
.addNextIntentWithParentStack(upIntent)
.startActivities();
finish();
} else {
NavUtils.navigateUpTo(this, upIntent);
}
return true;
}
return super.onOptionsItemSelected(item);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment