Use a persistent notification to allow the user to return to running Android app

后端 未结 5 777
情歌与酒
情歌与酒 2020-12-30 10:22

I am developing an app with numerous Activities. I would like to create a persistent notification that (more or less) says, \"AppName - Return to AppName\" that will be pre

5条回答
  •  南方客
    南方客 (楼主)
    2020-12-30 10:28

    I guess there is no easy way to do this but instead of adding a counter in the mainActivity I would extend Application:

    Base class for those who need to maintain global application state. You can provide your own implementation by specifying its name in your AndroidManifest.xml's tag, which will cause that class to be instantiated for you when the process for your application/package is created.

    I would mantein the logic there and have a method like:

    public Intent getIntentForLastActivityShown();
    

    to be called when the notification item is clicked.

提交回复
热议问题