Search code examples
androidandroid-dynamic-shortcuts

How to force close/refresh the app's shortcuts menu?


I have an App Shortcut (See:App shortcuts overview ) that calls an activity that immidietly calls finish() (after changing a small thing in the shareprefs).

so when I click on the shortcut - everything works, but the shortcut menu remains open. [The user doesn't notice the activity opening and closing and stays on the homescreen - with the shortcuts menu still open]

can I force close/force refresh it somehow?

[this gets annoying since I want to dynamically change the text of the shortvcut but this doesnt change unless i close this menu and re opens it]


Solution

  • well this is not the perfect answer but this will suffice the purpose

    instead of calling :

    finish();
    

    call this code after you change your shared preferences :

    Intent goToHomeIntent = new Intent(Intent.ACTION_MAIN);
    goToHomeIntent.addCategory(Intent.CATEGORY_HOME);
    goToHomeIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    startActivity(goToHomeIntent);
    

    what this does is that it takes the user to home screen of device

    hope it helps happy coding :)