开发者

Android: How do I always start the app from a particular activity?

开发者 https://www.devze.com 2023-01-26 00:43 出处:网络
I have an activity Alert, which is defined in the manifest like so : <activity android:name=\"Alert\"

I have an activity Alert, which is defined in the manifest like so :

        <activity android:name="Alert"
              android:label="@string/app_name"
    开发者_运维百科          android:theme="@android:style/Theme.Dialog"
              android:launchMode="singleInstance"
              android:noHistory="true">
    </activity>

I also have another activity Config which is a setting page for a homescreen widget and is defined as

        <activity android:name=".Config"
              android:label="@string/app_name">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

The Alert activity is shown when the user clicks on the widget. Now my problem is that, after running the application and returning to Home screen, when I long press the home-key and select the app, the Alert activity is shown. Is there a way to prevent this from happening and always start from the Config activity?


To illustrate this problem, you should understand the way Android handles activities. When you press 'home' button, your Alert is considered to be still alive, but it is in a pause mode. So, when you long press, it is switched back and just resume your previous top-of-the-pile activity, which is the Alert in this case.

So, you may consider to, in your onPause event of Alert, to tell Android to end the Activity instead of putting it to pause.

0

精彩评论

暂无评论...
验证码 换一张
取 消