Java 操作栏上的向上导航关闭Android中的应用程序。非活动输入连接
操作栏上的向上导航关闭Android中的应用程序。严格遵循android开发者的要求。我添加了.getSupportActionBar、.setDisplayHome,对我的菜单进行了扩展,将我的案例放在OnCreateOptions菜单中,但仍然不起作用Java 操作栏上的向上导航关闭Android中的应用程序。非活动输入连接,java,android,navigation,android-actionbar,up-navigation,Java,Android,Navigation,Android Actionbar,Up Navigation,操作栏上的向上导航关闭Android中的应用程序。严格遵循android开发者的要求。我添加了.getSupportActionBar、.setDisplayHome,对我的菜单进行了扩展,将我的案例放在OnCreateOptions菜单中,但仍然不起作用 public class AddressList extends ActionBarActivity { @Override protected void onCreate(Bundle savedInstanceState) {
public class AddressList extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_address_list);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
ListView listview = (ListView) findViewById(R.id.listView);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu_address_list, menu);
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.button:
Add();
return true;
case android.R.id.home:
NavUtils.navigateUpFromSameTask(this);
return true;
}
return super.onOptionsItemSelected(item);
}
这是我的清单文件,显示我已经添加了parentactivity名称和元数据
<activity
android:name=".SilentGeofence"
android:label="@string/title_activity_silent_geofence"
android:parentActivityName=".AddressList" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".AddressList" />
</activity>
我以前也有过同样的问题。尝试使用以下代码段。贷记到代码段中的链接:
case android.R.id.home:
//solution for the up navigation problem:
//http://stackoverflow.com/questions/13632480/android-build-a-notification-taskstackbuilder-addparentstack-not-working
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.
upIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
NavUtils.navigateUpTo(this, upIntent);
Log.v("recreate activity", "shouldUpRecreateTask = false");
}
在android:value中,尝试使用父活动的完整包名
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.example.AddressList" />
如果有人还需要答案,这里是我如何做到的
//First set Parent activity in your xml as shown above
<activity
android:name=".ChildActivity"
android:label="@string/title"
android:parentActivityName=".MainActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".MainActivity" />
</activity>
//Now you can simply get the parent Intent and use startActivity
@Override
public boolean onOptionsItemSelected(MenuItem item){
switch (item.getItemId()){
case android.R.id.home:
Intent upIntent=NavUtils.getParentActivityIntent(this);
//You might need to add some Launch Parameters like
upIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
startActivity(upIntent);
return true;
}
return super.onOptionsItemSelected(item);
}
您可以在此处找到有关这些启动参数的更多信息:
您是否收到任何错误消息?03-12 19:35:00.529 16221-16221/com.example.anusha.app W/IInputConnectionWrapper﹕ 在inactive InputConnection@joaquinWell上显示状态图标,您的日志绝对不完整。但问题似乎不在您发布的代码上。我知道它有点旧,但是,首先让我印象深刻的是,您向我们显示AddressListActivity的代码,然后在清单中显示它是SilentGeofence的父级。代码片段不应该在SilentGeofence中吗?