NecipAllef
NecipAllef

Reputation: 506

Best Practices for checking if App is running when notification is clicked

I've searched the internet and couldn't find any solution to this. Then I've came up with a solution, but I am not sure if it is elegant. I'll post my own solution as well.

Basically what I want to do is to check if application is running when notification is clicked, not when notification comes (I already know how to do the latter). The difference is that, a notification can come when app is running but user can click on it later when app is not running. So, I need to check if app is running when notification is clicked.

How to do that?

Upvotes: 2

Views: 1352

Answers (2)

fluffyBatman
fluffyBatman

Reputation: 6704

Here is one way of checking the current state of your application. Execute it when user taps on the notification and do whatever you need to do based on state of your app.

Upvotes: 1

NecipAllef
NecipAllef

Reputation: 506

Create an activity with no display, call it NotificationActivity. Use this activity for notification click and make the appIsRunning() check in that activity.

For creating an activity with no display, have these in AndroidManifest.xml:

    <activity
            android:name=".NotificationActivity"
            android:theme="@android:style/Theme.NoDisplay"
            android:noHistory="true"
            android:excludeFromRecents="true"/> 

For more info on invisible activity: http://androidblog.reindustries.com/android-cheats-and-tips-invisible-activity/

Upvotes: 1

Related Questions