Android – breaks the single top contract

This is the problem. I have an < activity alias > defined in my list as follows:

<activity
    android:name=".HomeActivity"/>

<activity-alias
    android:name=".MainActivity"
    android:targetActivity=".HomeActivity">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity-alias>

Now, the user starts mainactivity with the launcher icon, which is forwarded to homeactivity

I also have an intent to start homeactivity from the navigation drawer. It starts with intent.flag_ ACTIVITY_ SINGLE_ Top | starts with intent.flag_ ACTIVITY_ CLEAR_ Top Flag – reuse existing activity instances

The problem is that this doesn't work as expected. It actually creates a new instance of homeactivity (even if it's currently at the top and visible!). This happens because the activity background contains an entry for. Mainactivity, not the homeactivity it eventually forwards to

Question: I suspect this may or may not be a mistake in Android, but it's hard for me to find a decent solution. Ask for help here!

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>