简体   繁体   中英

Launch the same activity from both app launcher and notification when foreground service is running

My setup is the following:

  • Activity A (launched on initial app launch)
  • Activity B (starts a foreground service to records GPS data)

When the foreground service is started, I create a pending intent for the notification, and upon tapping it, Activity B is opened, which is the expected outcome.

While the foreground service is running, if I launch the app from the app launcher, it opens Activity A. Here, when the service is running, I need to launch Activity B.

My suggestion would be putting variable into SharedPreferences to indicate if the service is running and check it in your ActivityA. If service is running don't load any views and open ActivityB.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM