返回按钮退出应用程序 [英] BackButton quit the application

查看:208
本文介绍了返回按钮退出应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了我的应用程序麻烦,我后退按钮退出应用程序。
我的应用程序是一个SyncService,一切似乎都在清单伟大的,我检查了一天,没有回应...

I'm experiencing a trouble on my app, my backButton quit the application. My application is a SyncService, everything seems to be great in the Manifest, i check for one day with no response...

我已经检查launchmode改变的东西,我测试4并没有什么附加...
如果有人能对清单一看,这将是巨大的:

I already check if the launchmode change something, i test the 4 and nothing append... If someone can have a look on the manifest, it would be great :

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.smile.android.ldapsync" android:versionCode="12" android:versionName="1.5">
    <uses-permission android:name="android.permission.GET_ACCOUNTS" />
    <uses-permission android:name="android.permission.USE_CREDENTIALS" />
    <uses-permission android:name="android.permission.MANAGE_ACCOUNTS" />
    <uses-permission android:name="android.permission.AUTHENTICATE_ACCOUNTS" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.WRITE_SETTINGS" />
    <uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS" />
    <uses-permission android:name="android.permission.READ_CONTACTS" />
    <uses-permission android:name="android.permission.WRITE_CONTACTS" />
    <uses-permission android:name="android.permission.READ_SYNC_STATS" />
    <uses-permission android:name="android.permission.READ_SYNC_SETTINGS" />
    <uses-permission android:name="android.permission.WRITE_SYNC_SETTINGS" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /><application android:icon="@drawable/icon" android:label="@string/app_name" android:debuggable="true" android:enabled="true" android:persistent="true">
        <service android:name="com.smile.android.ldapsync.authenticator.LDAPAuthenticationService" android:exported="true" android:debuggable="true">
            <intent-filter>
                <action android:name="android.accounts.AccountAuthenticator" />
            </intent-filter>
            <meta-data android:name="android.accounts.AccountAuthenticator" android:resource="@xml/authenticator" />
        </service>
        <service android:name="com.smile.android.ldapsync.syncadapter.SyncService" android:exported="true" android:debuggable="true">
            <intent-filter>
                <action android:name="android.content.SyncAdapter" />
            </intent-filter>
            <meta-data android:name="android.content.SyncAdapter" android:resource="@xml/syncadapter" />
        </service>
        <activity android:name="com.smile.android.ldapsync.authenticator.LDAPAuthenticatorActivity" android:label="@string/ui_activity_title" android:excludeFromRecents="true">
            android:excludeFromRecents="true"
                <!--
                No intent-filter here! This activity is only ever launched by
                someone who explicitly knows the class name
            -->
        </activity>
    </application>
    <uses-sdk android:minSdkVersion="5" />
</manifest> 

感谢您;)

推荐答案

如果您preSS后退按钮,而在主活动OS明白这一点(您又名你的活动栈底推出的第一个)为用户已经完成,不会再回来很快的反对,认为这是理解为也许是用户想要恢复应用程序前检查别的东西

if you press back button while on the "main" activity (the first one you launched aka the bottom of your activity stack) the OS understand this as "the user is done and won't be back anytime soon" opposed as "home" button which is understood as "maybe the user wants to check something else before resuming the app"

所以,如果你不想让你的应用程序,以终止(Android应用程序终止OS杀死它,只有当,否则它会在内存潜伏,直到召回的),你需要重写后退按钮pressed回调

So, if you DO NOT want your app to "terminate" (an android app terminates only when the OS kills it, otherwise it will lurk in memory until recalled) you need to override the back button pressed callback

public void onBackPressed()

该API文档描述为:

which the api doc describes as:

时,活动检测返回键的用户的preSS调用。默认实现只完成当前活动,但您可以覆盖这做任何你想要的。

"Called when the activity has detected the user's press of the back key. The default implementation simply finishes the current activity, but you can override this to do whatever you want."

您可能只是忽略事件和吸收它喜欢蒂莫施勒塞尔建议,或者你可以做任何最拨款(如,推出另一项活动或离开屏幕之前杀死服务)

You might just ignore the event and absorb it like timo schloesser suggested or you can do whatever is most appropriated (like, launching another activity or killing services before leaving the screen)

编辑:您可能还需要检查从Activity类继承了moveTaskToBack的方法。我从来没有使用它,但它可能是你的问题非常有用。

you might also want to check the "moveTaskToBack" method inherited from Activity class. I have never used it but it might be useful to your problem.

这篇关于返回按钮退出应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆