stianboe stianboe - 1 year ago 157
Android Question

Open activity by clicking on the push notification from Parse

I want to receive a push notification from Parse and open an List activity and use intent.putextra("dataFromParse") before starting the activity.
I'm able to receive the push but only open the MainActivity by using this:

PushService.setDefaultPushCallback(this, MainActivity.class);

I want to have this as the default, but should also be able to start the List activity.
I have also tried using a customer receiver, but then I'm only able to directly open the activity when receiving the push, not when clicking it.


<receiver android:name="com.example.Push android:exported="false">
<action android:name="com.example.UPDATE_STATUS" />

public class Push extends BroadcastReceiver {

public void onReceive(Context context, Intent intent) {
//Start activity

The thing I'm not sure about is how I should capture the push in the background and say that it should open the List activity with the specific intent.putExtra("dataFromParse") when the user clicks the notification. Where should I code it and how? In the MainActivity, in the List activity, or do something other with the customer receiver?


Solved it, having default activity as MainActivity, but checking the intent, and if there is something in "com.parse.Data" I will start a new intent.

Intent intent = getIntent();
Bundle extras = intent.getExtras();
String jsonData = extras.getString("com.parse.Data");
JSONObject json = new JSONObject(jsonData);
String pushStore = json.getString("data");
if(pushStore!=null) {
    Intent pushIntent = new Intent();
    pushIntent.setClassName(MainActivity.this, "");
    pushIntent.putExtra("store", pushStore);

Then just send a push with json: { "alert" : "Test", "data" : "store1" }

@arvindwill Hope this will help.