In my MainActivity, I have a dialog which is opened if a flag in the intent is set. If the dialog was created, it is dismissed in onPause()
@Override
public void onPause() {
super.onPause();
if (_dialog!= null) {
_dialog.dismiss();
_dialog= null;
}
}
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
if (intentContainsFlag) {
_dialog = ....;
_dialog.show();
}
}
The dialog is to be opened if a ListView holder's button is pressed and builds an intent URI:
bttn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// The URL scheme is registered in the intent filter
String intentString = "http://open.example.com/myParameters";
v.getContext().startActivity(new Intent(Intent.ACTION_VIEW,
Uri.parse(intentString)));
}
});
The AndroidManigfest contains:
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:launchMode="singleTask"
android:screenOrientation="landscape" >
<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:scheme="http" android:host="open.example.com" android:pathPattern=".*"/>
<data android:scheme="https" android:host="open.example.com" android:pathPattern=".*"/>
</intent-filter>
....
The sdk versions are set to
minSdkVersion = 19
targetSdkVersion= 22
compileSdkVersion = 23
buildToolsVersion = 23
On Android < 7.1.1, everything works as expected: onNewIntent()
is called and the dialog is visible.
But on 7.1.1. devices
the MainActivity's onNewIntent
is called, then directly afterwards onPause
and onResume
. This means that the activity opens itself / comes to the foreground but the dialog was immediately closed.
A possible workaround is to close the dialog in onStop()
but I don't get why this happens on Android 7.1.1 - was something changed in the life cycle ?