ANDROID:简单的向上导航不起作用
Posted
技术标签:
【中文标题】ANDROID:简单的向上导航不起作用【英文标题】:ANDROID: Simple Up Navigation Not Working 【发布时间】:2015-05-17 03:31:29 【问题描述】:android 中的向上导航不起作用。我想做的就是回去。但是,每次我单击后退按钮时,它都会关闭应用程序。我跟着安卓开发者。我的错误日志甚至没有说任何有用的东西,所以我不知道为什么会这样。我的第一个主视图是一个谷歌地图活动,我的第二个视图是一个空白活动,上面有一个列表视图。
这是我的错误日志
03-14 11:20:56.261 19816-19816/com.example.anusha.app I/SELinux Function:selinux_android_load_priority , priority [2] , priority version is VE=SEPF_SAMSUNG-SGH-I337_4.4.4_0032
03-14 11:20:56.261 19816-19816/com.example.anusha.app E/dalvikvm﹕ >>>>> Normal User
03-14 11:20:56.261 19816-19816/com.example.anusha.app E/dalvikvm﹕ >>>>> com.example.anusha.app [ userId:0 | appId:10250 ]
03-14 11:20:56.271 19816-19816/com.example.anusha.app D/dalvikvm﹕ Late-enabling CheckJNI
03-14 11:20:56.412 19816-19816/com.example.anusha.app I/x﹕ Making Creator dynamically
03-14 11:20:56.472 19816-19816/com.example.anusha.app I/Google Maps Android API﹕ Google Play services client version: 6587000
03-14 11:20:56.472 19816-19816/com.example.anusha.app I/Google Maps Android API﹕ Google Play services package version: 6776038
03-14 11:20:57.453 19816-19816/com.example.anusha.app D/dalvikvm﹕ GC_FOR_ALLOC freed 4226K, 23% free 20774K/26904K, paused 41ms, total 42ms
03-14 11:20:57.543 19816-19816/com.example.anusha.app I/dalvikvm﹕ Could not find method android.content.pm.PackageManager.getPackageInstaller, referenced from method com.google.android.gms.common.ew.c
03-14 11:20:57.543 19816-19816/com.example.anusha.app W/dalvikvm﹕ VFY: unable to resolve virtual method 441: Landroid/content/pm/PackageManager;.getPackageInstaller ()Landroid/content/pm/PackageInstaller;
03-14 11:20:57.543 19816-19816/com.example.anusha.app D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x000f
03-14 11:20:57.613 19816-19957/com.example.anusha.app W/ActivityThread﹕ ClassLoader.loadClass: The class loader returned by Thread.getContextClassLoader() may fail for processes that host multiple applications. You should explicitly specify a context class loader. For example: Thread.setContextClassLoader(getClass().getClassLoader());
03-14 11:20:57.673 19816-19816/com.example.anusha.app D/AbsListView﹕ Get MotionRecognitionManager
03-14 11:20:57.823 19816-19816/com.example.anusha.app D/dalvikvm﹕ GC_FOR_ALLOC freed 1176K, 20% free 21645K/26904K, paused 53ms, total 53ms
03-14 11:20:57.983 19816-19816/com.example.anusha.app D/Activity﹕ #1 setTransGradationModeColor false
03-14 11:20:58.023 19816-19816/com.example.anusha.app I/Adreno-EGL﹕ <qeglDrvAPI_eglInitialize:381>: EGL 1.4 QUALCOMM build: (CL3869936)
OpenGL ES Shader Compiler Version: 17.01.11.SPL
Build Date: 01/17/14 Fri
Local Branch:
Remote Branch:
Local Patches:
Reconstruct Branch:
03-14 11:20:58.143 19816-19816/com.example.anusha.app D/OpenGLRenderer﹕ Enabling debug mode 0
03-14 11:20:58.353 19816-19981/com.example.anusha.app D/dalvikvm﹕ GC_FOR_ALLOC freed 1659K, 19% free 22025K/26904K, paused 72ms, total 73ms
03-14 11:20:58.614 19816-19972/com.example.anusha.app D/dalvikvm﹕ GC_FOR_ALLOC freed 1364K, 18% free 22317K/26904K, paused 48ms, total 48ms
03-14 11:20:58.744 19816-19972/com.example.anusha.app D/dalvikvm﹕ GC_FOR_ALLOC freed 91K, 17% free 22589K/26904K, paused 45ms, total 45ms
03-14 11:20:58.804 19816-19981/com.example.anusha.app D/dalvikvm﹕ GC_FOR_ALLOC freed 367K, 16% free 23090K/27344K, paused 35ms, total 35ms
03-14 11:20:59.154 19816-19972/com.example.anusha.app D/dalvikvm﹕ GC_FOR_ALLOC freed 11145K, 33% free 27756K/41368K, paused 47ms, total 47ms
03-14 11:20:59.234 19816-19981/com.example.anusha.app D/dalvikvm﹕ GC_FOR_ALLOC freed 4822K, 44% free 23455K/41368K, paused 34ms, total 34ms
03-14 11:20:59.244 19816-19981/com.example.anusha.app I/dalvikvm-heap﹕ Grow heap (frag case) to 30.763MB for 4194320-byte allocation
03-14 11:20:59.374 19816-19981/com.example.anusha.app D/dalvikvm﹕ GC_FOR_ALLOC freed 4367K, 44% free 23465K/41368K, paused 35ms, total 35ms
03-14 11:20:59.374 19816-19981/com.example.anusha.app I/dalvikvm-heap﹕ Grow heap (frag case) to 30.773MB for 4194320-byte allocation
03-14 11:20:59.495 19816-19981/com.example.anusha.app D/dalvikvm﹕ GC_FOR_ALLOC freed 4234K, 44% free 23466K/41368K, paused 46ms, total 46ms
03-14 11:20:59.495 19816-19981/com.example.anusha.app I/dalvikvm-heap﹕ Grow heap (frag case) to 30.774MB for 4194320-byte allocation
03-14 11:20:59.595 19816-19981/com.example.anusha.app D/dalvikvm﹕ GC_FOR_ALLOC freed 4234K, 44% free 23466K/41368K, paused 36ms, total 36ms
03-14 11:20:59.595 19816-19981/com.example.anusha.app I/dalvikvm-heap﹕ Grow heap (frag case) to 30.774MB for 4194320-byte allocation
03-14 11:20:59.705 19816-19981/com.example.anusha.app D/dalvikvm﹕ GC_FOR_ALLOC freed 4240K, 44% free 23458K/41368K, paused 42ms, total 42ms
03-14 11:20:59.705 19816-19981/com.example.anusha.app I/dalvikvm-heap﹕ Grow heap (frag case) to 30.766MB for 4194320-byte allocation
03-14 11:20:59.805 19816-19981/com.example.anusha.app D/dalvikvm﹕ GC_FOR_ALLOC freed 4233K, 44% free 23459K/41368K, paused 40ms, total 40ms
03-14 11:20:59.805 19816-19981/com.example.anusha.app I/dalvikvm-heap﹕ Grow heap (frag case) to 30.767MB for 4194320-byte allocation
03-14 11:21:00.075 19816-19981/com.example.anusha.app D/dalvikvm﹕ GC_FOR_ALLOC freed 6133K, 44% free 23465K/41368K, paused 79ms, total 79ms
03-14 11:21:12.057 19816-19816/com.example.anusha.app I/dalvikvm﹕ Could not find method android.view.ViewGroup.onNestedScrollAccepted, referenced from method android.support.v7.internal.widget.ActionBarOverlayLayout.onNestedScrollAccepted
03-14 11:21:12.057 19816-19816/com.example.anusha.app W/dalvikvm﹕ VFY: unable to resolve virtual method 11751: Landroid/view/ViewGroup;.onNestedScrollAccepted (Landroid/view/View;Landroid/view/View;I)V
03-14 11:21:12.057 19816-19816/com.example.anusha.app D/dalvikvm﹕ VFY: replacing opcode 0x6f at 0x0000
03-14 11:21:12.067 19816-19816/com.example.anusha.app I/dalvikvm﹕ Could not find method android.view.ViewGroup.onStopNestedScroll, referenced from method android.support.v7.internal.widget.ActionBarOverlayLayout.onStopNestedScroll
03-14 11:21:12.067 19816-19816/com.example.anusha.app W/dalvikvm﹕ VFY: unable to resolve virtual method 11757: Landroid/view/ViewGroup;.onStopNestedScroll (Landroid/view/View;)V
03-14 11:21:12.067 19816-19816/com.example.anusha.app D/dalvikvm﹕ VFY: replacing opcode 0x6f at 0x0000
03-14 11:21:12.067 19816-19816/com.example.anusha.app I/dalvikvm﹕ Could not find method android.support.v7.internal.widget.ActionBarOverlayLayout.stopNestedScroll, referenced from method android.support.v7.internal.widget.ActionBarOverlayLayout.setHideOnContentScrollEnabled
03-14 11:21:12.067 19816-19816/com.example.anusha.app W/dalvikvm﹕ VFY: unable to resolve virtual method 9402: Landroid/support/v7/internal/widget/ActionBarOverlayLayout;.stopNestedScroll ()V
03-14 11:21:12.067 19816-19816/com.example.anusha.app D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x000e
03-14 11:21:12.067 19816-19816/com.example.anusha.app I/dalvikvm﹕ Could not find method android.content.res.TypedArray.getChangingConfigurations, referenced from method android.support.v7.internal.widget.TintTypedArray.getChangingConfigurations
03-14 11:21:12.067 19816-19816/com.example.anusha.app W/dalvikvm﹕ VFY: unable to resolve virtual method 537: Landroid/content/res/TypedArray;.getChangingConfigurations ()I
03-14 11:21:12.067 19816-19816/com.example.anusha.app D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x0002
03-14 11:21:12.067 19816-19816/com.example.anusha.app I/dalvikvm﹕ Could not find method android.content.res.TypedArray.getType, referenced from method android.support.v7.internal.widget.TintTypedArray.getType
03-14 11:21:12.067 19816-19816/com.example.anusha.app W/dalvikvm﹕ VFY: unable to resolve virtual method 559: Landroid/content/res/TypedArray;.getType (I)I
03-14 11:21:12.067 19816-19816/com.example.anusha.app D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x0002
03-14 11:21:12.107 19816-19816/com.example.anusha.app D/AbsListView﹕ Get MotionRecognitionManager
03-14 11:21:12.117 19816-19816/com.example.anusha.app D/Activity﹕ #1 setTransGradationModeColor false
03-14 11:21:12.637 19816-19816/com.example.anusha.app D/AbsListView﹕ onDetachedFromWindow
03-14 11:21:14.019 19816-19816/com.example.anusha.app V/recreate activity﹕ shouldUpRecreateTask = false
03-14 11:21:14.699 19816-19816/com.example.anusha.app D/AbsListView﹕ onDetachedFromWindow
03-14 11:23:18.887 21337-21337/com.example.anusha.app I/SELinux﹕ Function: selinux_android_load_priority , priority [2] , priority version is VE=SEPF_SAMSUNG-SGH-I337_4.4.4_0032
.
@Override
public boolean onOptionsItemSelected(MenuItem item)
switch (item.getItemId())
case R.id.button:
Add();
return true;
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.
upIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
NavUtils.navigateUpTo(this, upIntent);
Log.v("recreate activity", "shouldUpRecreateTask = false");
return true;
return super.onOptionsItemSelected(item);
这是我的清单
<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>
【问题讨论】:
你只是想让它重新创建后退按钮效果? @joao2fast4u 是的。但它一直关闭我尝试过的应用程序 NavUtils.navigateUpFromSameTask(this);但这也不起作用。 地图活动是列表活动的父项吗? 是的,我的主要视图是地图活动。然后我按下一个按钮,它进入列表活动(AddressList)。我希望用户能够从 AddressList 返回 MapsActivity。 @KrishnaTejaVelagapudi 如果它是父活动,则向上按钮将带您进入地图活动,而据我所知,您无需执行任何操作 【参考方案1】: Button button2 = (Button) findViewById(R.id.button2); button2.setOnClickListener(new View.OnClickListener() public void onClick(View v ) Intent intent = new Intent(MapsActivity.this, AddressList.class); startActivity(intent); );
删除完成,它会工作
【讨论】:
当你说完成(); android 不会将活动保存在 backstack 中 finish() 的工作原理。如果您不希望在 backstack 中进行活动,请使用 finsih();在有意图地开始另一个活动之后,否则你不会说finish()【参考方案2】:如果您只想单击操作栏主页按钮并返回,请将case android.R.id.home:
中的代码替换为:
super.onBackPressed();
break;
这将重新创建后退按钮按下。
【讨论】:
没用。你应该建议我做什么?我已经尝试了所有解决方案。我想我应该退出 upNavigation 并制作自己的后退按钮 @joao2fast4u以上是关于ANDROID:简单的向上导航不起作用的主要内容,如果未能解决你的问题,请参考以下文章