Created
August 16, 2014 09:51
-
-
Save nein37/121b3ccd3d9248d03a6a to your computer and use it in GitHub Desktop.
Upボタンの実装メモ ref: http://qiita.com/nein37/items/6a063f5462400036920b
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<activity | |
android:name=".ChildActivity" | |
android:launchMode="singleTop" | |
android:parentActivityName=".ParentActivity"> | |
<meta-data | |
android:name="android.support.PARENT_ACTIVITY" | |
android:value=".ParentActivity" /> | |
</activity> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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?) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Override | |
public boolean onOptionsItemSelected(MenuItem item) { | |
switch (item.getItemId()) { | |
case android.R.id.home: | |
NavUtils.navigateUpFromSameTask(this); | |
return true; | |
} | |
return super.onOptionsItemSelected(item); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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