2

I'm porting an app from iOS to Android. We use Parse as our back end. I'm currently working on the implementation of PUSH notifications.

All is going well in that I am able to receive PUSH notifications in the Android app. Now, I want to code the app so that it acts correctly depending upon the current state of the app.

From Googling/reading, I think the following is true:

  1. If the user has force-closed your app, your app will never run code again unless the user re-initiates a launch. Is this also true if the app crashes?
  2. Otherwise, the app receives the notification.

What I'm trying to figure out is when to take what actions. For instance, in my iOS app, the following cases lead to the associated actions:

  1. If the app is launched from user "clicking on" a PUSH notification, I go directly to the screen for the content in question. I do not ask the user if they want to view the content, but I assume that clicking the PUSH notification indicates this desire.
  2. If the app is already running when the PUSH notification is received, I execute the following logic:
    • If the content related to the PUSH notification is already on-screen, I simply discard the notification.
    • If the content is NOT on-screen, I display a pop-up to the user asking if they wish to view the content. Only if they click "Yes" do I then show them the content. This normally involves UI navigation.

So, I'm wondering how I determine user interactions for Android like I do in iOS, specifically:

  1. How do I know if the user tapped on a PUSH notification to launch the app (whether it was already running or not)?
  2. How do I know if my app is already on-screen when the PUSH notification is received?

I saw this question, but the answers seem to be more high-level about how GCM/PUSH works, which I already understand.

I saw this question, but the author of the answer didn't mention how they check the app's state. I think the how of that bit is what I'm really after.

I read this article, but I didn't see a way to determine the level of importance of the process that represents this app (did I word that correctly?).

This answer led me to this article, which might be the way to determine the level of importance of the process, but then it got me wondering whether there were any "gotchas" or further details that I would need to know, such as whether a given importance always represents a particular app lifecycle state or not.

The best info I could find at http://developer.android.com was this article, which is a very basic PUSH receiver, which I already have working.

Here's the skeleton implementation that extends ParsePushBroadcastReceiver:

public class ParsePushNotificationReceiver extends ParsePushBroadcastReceiver {
    private final String TAG = "ParsePushBroadcastReceiver";

    @Override
    public void onReceive(Context context, Intent intent) {
        Log.d(TAG, "onReceive() fired.");
        Log.d(TAG, "intent: " + intent.toString());
        Log.d(TAG, "extras: " + intent.getExtras().toString());
        super.onReceive(context, intent);
    }

    @Override
    protected void onPushReceive(Context context, Intent intent) {
        Log.d(TAG, "onPushReceive() fired.");
        Log.d(TAG, "intent: " + intent.toString());
        Log.d(TAG, "extras: " + intent.getExtras().toString());
        super.onPushReceive(context, intent);
    }

    @Override
    protected void onPushDismiss(Context context, Intent intent) {
        Log.d(TAG, "onPushDismiss() fired.");
        super.onPushDismiss(context, intent);
    }

    @Override
    protected void onPushOpen(Context context, Intent intent) {
        Log.d(TAG, "onPushOpen() fired.");
        super.onPushOpen(context, intent);
    }

    @Override
    protected Class<? extends Activity> getActivity(Context context, Intent intent) {
        Log.d(TAG, "getActivity() fired.");
        return super.getActivity(context, intent);
    }

    @Override
    protected int getSmallIconId(Context context, Intent intent) {
        Log.d(TAG, "getSmallIconId() fired.");
        return super.getSmallIconId(context, intent);
    }

    @Override
    protected Bitmap getLargeIcon(Context context, Intent intent) {
        Log.d(TAG, "getLargeIcon() fired.");
        return super.getLargeIcon(context, intent);
    }

    @Override
    protected Notification getNotification(Context context, Intent intent) {
        return super.getNotification(context, intent);
    }
}
Community
  • 1
  • 1
mbm29414
  • 11,558
  • 6
  • 56
  • 87

0 Answers0