主要活动中的后退按钮 - 正常行为吗?
如果我在主要活动中按后退按钮,则会出现黑屏。这是正常行为吗?为了解决这个问题,我输入了以下代码 - 这是一个好的解决方法吗?
public void onBackPressed() {
return;
}
编辑
这里是清单,以防错误:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.example.DatabaseImport"
android:versionCode="1"
android:versionName="1.0"
android:screenOrientation="portrait">
<uses-sdk android:minSdkVersion="8" />
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".Main"
android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".DetailView"
android:label="@string/detail_label"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
>
</activity>
</application>
</manifest>
If I press the back button from my main activity I get a black screen. Is this normal behavior ? To get round this I have put in the following code - is this an ok work around ?
public void onBackPressed() {
return;
}
EDIT
Here is the manifest in case it is wrong :
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.example.DatabaseImport"
android:versionCode="1"
android:versionName="1.0"
android:screenOrientation="portrait">
<uses-sdk android:minSdkVersion="8" />
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".Main"
android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".DetailView"
android:label="@string/detail_label"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
>
</activity>
</application>
</manifest>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这不是正常的行为。
您是否有一个初始活动来开始您的“主要”活动?
你有重要的听众吗?
听起来您有另一个活动调用您的“主要”活动,然后单击“主要”活动将返回到未完成的初始活动。
编辑:
从您的编辑中我发现您在主要活动之前没有其他活动,因此唯一的假设是您在 onStop / onPause 或 onDestroy 中做错了什么。请粘贴这些。
It's not a normal behavious.
Do you have an initial activity from which you start your "main" activity?
Do you have any key listeners?
It sounds like you have another activity calling your "main" activity and clicking back in the "main" activity goes back to the unfinished initial activity.
EDIT:
From your edit I see you don't have an additional activity before the main one, so the only assumption is that you're doing something wrong in onStop / onPause or onDestroy. Please paste these.
返回按钮默认调用
finish()
。您的 Activity 中的onPause()
或启动您的 Activity 的onStart()
和onResume()
可能存在问题。Back button calls
finish()
by default. There could be problem inonPause()
in your Activity or inonStart()
andonResume()
of Activity that started yours.这不是正常行为。在主要活动中按后退按钮应该会将您带到主屏幕。
您确定这是第一个活动吗?你的清单应该看起来像这样:
It is not normal behavior. Pressing back button in main activity should take you to the home screen.
are you sure it's the first activity? your manifest should look something like this:
让
onPause
和onStop
回调尽可能简单。可能是这些方法中的某些事情导致了延迟。Keep the
onPause
andonStop
callbacks as light as possible. May be some thing in these methods is causing the delay.