Why permission dialog disappear when application is open again?

android permissions best practices
android check permission programmatically
android app permissions developer
shouldshowrequestpermissionrationale
how to ask permission (runtime) again if the user deny for the first time
android app permissions list
android-camera permission example
read external storage permission android

I have added READ_PHONE_STATE permission in my project.

Scenario: I am just opening my application and I get Permission alert "Allow My Application to make and manage phone calls ?" Now I am moving my application in background and again opening by tap on My Application icon Result: "Allow My Application to make and manage phone calls ?" Permission pop up get disappears.

Can any one tell why this behaviour? Note: I am using launchMode="singleInstance" and when using launchMode="standard" all is working fine.

Sharing my code :

<?xml version="1.0" encoding="utf-8"?>

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity android:name=".MainActivity" android:launchMode="singleTask">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

public class MainActivity extends AppCompatActivity {

public static final Integer REQUEST_CODE_FOR_PERMISSION = 0x1;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    askForPermission(this, Manifest.permission.READ_PHONE_STATE, REQUEST_CODE_FOR_PERMISSION);
}

public static void askForPermission(Activity context, String permission, Integer requestCode) {
    if ((Build.VERSION.SDK_INT >= 23) && (context != null) && (TextUtils.isEmpty(permission) == false)) {
        ActivityCompat.requestPermissions(context, new String[]{permission}, requestCode);
    }
}}

Based on singleTask behaviour

If an instance of the activity already exists in a separate task, the system routes the intent to the existing instance through a call to its onNewIntent() method, rather than creating a new instance.

https://developer.android.com/guide/components/activities/tasks-and-back-stack#TaskLaunchModes

I was able to fix this issue by handling the code in

onNewIntent(Intent intent)

@Override
protected void onNewIntent(Intent intent) {
    super.onNewIntent(intent);
    askForPermission(this, Manifest.permission.READ_PHONE_STATE, REQUEST_CODE_FOR_PERMISSION);
}

How to forget the "Never ask again" choice in Android M runtime , How do I get rid of never ask again permission on Android? Troubleshooting common permissions and security-related issues in Microsoft ASP.NET To customize this column to your needs, we want to invite you to submit your ideas about topics that interest you and issues that you want to see addressed in future Knowledge Base articles and Support Voice columns.


Try this,

public class MainActivity extends AppCompatActivity {

    public static final Integer REQUEST_CODE_FOR_PERMISSION = 0x1;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

    }

    @override
    private void onResume(){
    askForPermission(this, Manifest.permission.READ_PHONE_STATE, REQUEST_CODE_FOR_PERMISSION);
    }

    public static void askForPermission(Activity context, String permission, Integer requestCode) {
        if ((Build.VERSION.SDK_INT >= 23) && (context != null) && (TextUtils.isEmpty(permission) == false)) {
            ActivityCompat.requestPermissions(context, new String[]{permission}, requestCode);
        }
    }}

Understanding Permissions in the Android World, . These include accessing the camera, contacts, location, microphone, sensors, SMS, and storage. Hello, I'm using DAVdroid 1.6.5-play on my Samsung Galaxy A3 (2017) with Android 6.0.1 to synchronize Calendar, Contacts and Tasks with nextcloud 12.0.1. Every time I close the OpenTask app manually and open it again, all tasks are gone.


Call finish() in onBackPressed()

@Override
    public void onBackPressed() {
        super.onBackPressed();
        finish();
    }

This will launch activity again and your code will work in onCreate()

What Android app permissions mean and how to use them, Based on singleTask behaviour. If an instance of the activity already exists in a separate task, the system routes the intent to the existing  You can see the dialog box open but then it closes and it makes Solidworks go behind another application that you have open such as Outlook. Once the dialog box disappears I can't even minimize Solidworks. The dialog box is definitely waiting for an answer. 3. I'll need to pay more attention,


Use Runtime Permission like this:

 public class MainActivity extends Activity {
        private static final int PERMISSION_REQUEST_CODE = 200;
        Context context;
        Activity activity;

        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            context = this;
            activity = this;
            setContentView(R.layout.activity_splash);
            if (!checkPermission()) {
                OpenActivity();
            } else {
                if (checkPermission()) {
                    requestPermissionAndContinue();
                } else {
                    OpenActivity();
                }
            }
        }

        private boolean checkPermission() {
            return ContextCompat.checkSelfPermission(this, READ_PHONE_STATE) != PackageManager.PERMISSION_GRANTED;
        }

        private void requestPermissionAndContinue() {
            if (ContextCompat.checkSelfPermission(this, READ_PHONE_STATE) != PackageManager.PERMISSION_GRANTED) {

                if (ActivityCompat.shouldShowRequestPermissionRationale(this, READ_PHONE_STATE)) {
                    AlertDialog.Builder alertBuilder = new AlertDialog.Builder(this);
                    alertBuilder.setCancelable(true);
                    alertBuilder.setTitle("Permission necessary");
                    alertBuilder.setMessage("STORAGE permission is necessary to write event!!!");
                    alertBuilder.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
                        @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
                        public void onClick(DialogInterface dialog, int which) {
                            ActivityCompat.requestPermissions(SplashActivityANother.this, new String[]{READ_PHONE_STATE,
                            }, PERMISSION_REQUEST_CODE);
                        }
                    });
                    AlertDialog alert = alertBuilder.create();
                    alert.show();
                    Log.e("", "permission denied, show dialog");
                } else {
                    ActivityCompat.requestPermissions(this, new String[]{READ_PHONE_STATE
                    }, PERMISSION_REQUEST_CODE);

                }
            } else {
                OpenActivity();

            }
        }

        @Override
        public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {

            if (requestCode == PERMISSION_REQUEST_CODE) {
                if (permissions.length > 0 && grantResults.length > 0) {

                    boolean flag = true;
                    for (int i = 0; i < grantResults.length; i++) {
                        if (grantResults[i] != PackageManager.PERMISSION_GRANTED) {
                            flag = false;
                        }
                    }
                    if (flag) {
                        OpenActivity();
                    } else {
                        finish();
                    }

                } else {
                    finish();
                }
            } else {
                super.onRequestPermissionsResult(requestCode, permissions, grantResults);
            }
        }

        private void OpenActivity() {
            Intent i = new Intent(MainActivity.this, SecondActivity.class);
            startActivity(i);
        }
    }

and Add <uses-permission android:name="android.permission.READ_PHONE_STATE" /> in to menifist file.

Hope this Helps you

Why permission dialog disappear when application is open again?, Background (do not kill) the app. Re-open the app --> Observe: the permissions dialog comes back up. Pressing Deny stops app from opening. If you have allow once a permission to your application then second time it don't show dialog until manually revoke permission because you have already given permission for that. And if you want to check every time then you need to add code in you onResume() method.


When permissions dialog is presented, and the app is , If the user is running Android 6.0 (API level 23) or later, every time the user tries some new app feature that requires a permission, the app has to interrupt the  Using the iOS dialog for pre-permission. The first dialog (shown in the middle above) would set a local flag in the app that they’d said no, but it didn’t set it as “Deny” in the OS.


App permissions best practices, Overview · Dim the system bars · Hide the status bar · Hide the Add permissions to the manifest; Check for permissions; Request permissions In that case, any time an app uses requestPermissions() to ask for that permission again, runtime permissions—that is, devices running Android 6.0 (API level  If I don't use the task, then it still disappears but it stays a bit longer than before. I am developing an application which depends heavily on location, so I need to check the location in a task and bring up certain view to the user, that is why I had a binding attached to visibility of button. Here is the updated code and video.


Request App Permissions, Facebook's existing icons for the information items requested by a permission. For example, for “access photos” and “access checkins” permissions, we use the photo and location If the permission is a required permission, the deny button disappears. Investigating the Animation of Application Permission Dialogs 151. The dialog box doesn’t appear if you open the app in Power Apps Studio or Power Apps Mobile. For more information about shared connections, see Share app resources . When Power Apps generates an app from data, the field used for sorting and searching isn't automatically configured .