I have an Activity that can be launched directly from the browser by calling url.
Operation code:
public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Uri data = getIntent().getData(); Log.d(getClass().getName(), "onCreate data=" + data); getIntent().replaceExtras(new Bundle()); getIntent().setAction(""); getIntent().setData(null); getIntent().setFlags(0); if (data != null && isValidUrl(data)) {
Application manifest code:
... <activity android:name=".MainActivity"> <intent-filter> <action android:name="android.intent.action.MAIN"/> <category android:name="android.intent.category.LAUNCHER"/> </intent-filter> <intent-filter> <action android:name="android.intent.action.VIEW"/> <category android:name="android.intent.category.DEFAULT"/> <category android:name="android.intent.category.BROWSABLE"/> <data android:host="example.com" android:pathPrefix="/" android:scheme="http"/> </intent-filter> </activity> ...
This code works just fine. When I open the application from the browser using the link ( http://example.com/somepage.html ), I have this output:
D/com.package.MainActivity: onCreate data=http:
But if I leave the application (using the "Back" button) and open the application again, from the last menu I will get the same result:
D/com.package.MainActivity: onDestroy D/com.package.MainActivity: onCreate data=http:
I want to clear the intent data in the onCreate method. Or is there a way to detect when an application starts from a recent menu?
UPD: I tried to do this:
@Override protected void onDestroy() { super.onDestroy(); getIntent().replaceExtras(new Bundle()); getIntent().setAction(""); getIntent().setData(null); getIntent().setFlags(0); Log.d(MainActivity.class.getName(), "onDestroy"); }
But that does not help.
source share