Android will move back to the app from Android settings

I get an inconsistent user interface due to how Android bounces off Android settings.

In my application, the user must give my application access ACTION_USAGE_ACCESS_SETTINGSto which I access with the following:

Intent intent = new Intent(Settings.ACTION_USAGE_ACCESS_SETTINGS);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);

After turning on the settings for inclusion for my application, I need the user to return to my application. The only way I know about this is to press the back button on the phone (I would like to know if it is possible to automatically return after the setting has been switched !!!?).

Now one of two things will happen:

1) The user has not used the Android settings recently, so he has not yet been opened (i.e. open in the open applications box). The first press of the "Back" button will bring them to my application as you wish.

2) The user recently used the Android settings. Thus, the settings have already been opened in the application box. Now, when the user clicks the button, Android selects them back through each settings page that they used recently (i.e. the Back button takes them through its history on the Android settings pages). To exit Android settings, it may take 2, 3 or 4 clicks of the "Back" button and return to my application. Obviously this is a terrible UI / UX, and I was wondering if there is a better way?

, Google "" , . , .

!

+4
4

, , , 3 .

1) @CommonsWare, FLAG_ACTIVITY_NEW_TASK, , , , , .

2) , :

Intent intent = new Intent(Settings.ACTION_USAGE_ACCESS_SETTINGS);
                    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
                    intent.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
                    startActivity(intent);

, 1 . .

3) . , , , , Google App. .., , Android , . :

Handler handler = new Handler();

Runnable checkSettingOn = new Runnable() {

    @Override
    //@TargetApi(23)
    public void run() {
        Log.d(TAG, "run: 1");
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
            Log.d(TAG, "run: 2");
            return;
        }
        if (isAccessGranted()) {
            Log.d(TAG, "run: 3");
            //You have the permission, re-launch MainActivity
            Intent i = new Intent(MainActivity.this, MainActivity.class);
            Log.d(TAG, "run: 4");
            i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
            startActivity(i);
            return;
        }
        handler.postDelayed(this, 200);
    }
};

, Android, :

handler.postDelayed(checkSettingOn, 1000);

, - .

+1

. , , ... . , . , , .

, Bluetooth , , bluetooth . , , , .

ComponentName cn = new ComponentName("com.android.settings", 
                   "com.android.settings.bluetooth.BluetoothSettings");
+1

, , , , 500 , , .
singleTask/singleInstance , . .

.

+1

, , . . , . , , , .

Uri uri = Uri.fromParts("package", getPackageName(), null);
Intent intent = new Intent();                            
intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
intent.setData(uri);
startActivity(intent);
0

Source: https://habr.com/ru/post/1689717/


All Articles