Android 活动启动导航不工作
我有一个活动,应该能够导航到它的父级。我是这样在清单中声明的:Android 活动启动导航不工作,android,android-activity,Android,Android Activity,我有一个活动,应该能够导航到它的父级。我是这样在清单中声明的: <activity android:name="com.myapp.SeminarActivity" android:label="@string/app_name" android:launchMode="singleTop" android:theme="@style/Theme.AppCompat.Light" android:paren
<activity
android:name="com.myapp.SeminarActivity"
android:label="@string/app_name"
android:launchMode="singleTop"
android:theme="@style/Theme.AppCompat.Light"
android:parentActivityName="com.myapp.SeminarOverviewActivity">
<!-- Parent activity meta-data to support 4.0 and lower -->
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.myapp.SeminarOverviewActivity" />
</activity>
但没有效果。在我的测试中,总是使用上面截取的其他部分。我不明白问题是什么?你在后退吗?您是否希望通过这样做来访问父活动?我在ActionBar左角按back。我想转到我在Manifest SeminarOverviewActivity中声明的活动,即使实际的活动不是从它开始的。
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
// Respond to the action bar's Up/Home button
case android.R.id.home:
Intent upIntent = NavUtils.getParentActivityIntent(this);
if (NavUtils.shouldUpRecreateTask(this, upIntent)) {
// This activity is NOT part of this app's task, so create a new task
// when navigating up, with a synthesized back stack.
TaskStackBuilder.create(this)
// Add all of this activity's parents to the back stack
.addNextIntentWithParentStack(upIntent)
// Navigate up to the closest parent
.startActivities();
} else {
// This activity is part of this app's task, so simply
// navigate up to the logical parent activity.
NavUtils.navigateUpTo(this, upIntent);
}
}
return super.onOptionsItemSelected(item);
}