Receive custom intent without activity restart

流过昼夜 提交于 2019-12-12 17:25:42

问题


I have a TextView with some linkification(twitter style):

Pattern pattern1 = Pattern.compile("@\\w+");
Linkify.addLinks(textView, pattern1, "my_activity://one=");
Pattern pattern2 = Pattern.compile("#\\w+");
Linkify.addLinks(textView, pattern2, "my_activity://two=");

Activity declared in manifest with following intent filter:

<intent-filter>
    <action android:name="android.intent.action.VIEW" />

    <category android:name="android.intent.category.BROWSABLE" />
    <category android:name="android.intent.category.DEFAULT" />

    <data android:scheme="my_activity" />
</intent-filter>

Intent gets caught in the onNewIntent method of the activity but the activity gets restarted before that(I assume this is default behaviour).

Is there a way to receive such intent without restarting activity?


回答1:


Looks like launchMode is the problem. You shouldn't use singleInstance, as that is only for HOME-screen replacements. You should try singleTop. That should be enough for what you are trying to do.



来源:https://stackoverflow.com/questions/11225687/receive-custom-intent-without-activity-restart

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!