Android: always got the old intent when opening li

2019-08-14 06:48发布

问题:

I want to achieve "launch App from web" and I have 2 ready-to-use links in my webpage. Opening either of the links did call the activity SchemeRedirectActivity and get the correct intent. The problem is when I store(don't close) the links in phone browser separately and:

open one link from browser > press Recent Apps key(e.g.the right hardware key on device) > open another link, getIntent() always gives me the old intent except the first time opening each link.

Manifest:

<activity
        android:name=".SchemeRedirectActivity"
        android:screenOrientation="sensorPortrait">
        <intent-filter>
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT"/>
            <category android:name="android.intent.category.BROWSABLE" />
        </intent-filter>
</activity>

SchemeRedirectActivity:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    intent = getIntent(); //always got the old intent here
    Uri data = intent.getData();
}

The solutions from internet don't work for my case, even if I add android:launchMode="singleTask" / "singleTop" to manifest file, my onNewIntent() is never launched:

@Override
protected void onNewIntent(Intent intent) {
    super.onNewIntent(intent);

    Log.d("intent", "onNewIntent "); //never launched
    Uri data = intent.getData();

}

What is wrong with the process and how can I fix it please? *Sorry if my question is not clear, thanks.