用户点击Parse.com通知时打开活动

时间:2015-03-12 17:01:25

标签: android parse-platform push-notification android-notifications android-broadcast

我正在使用Parse.com进行通知,我想在用户点击传入通知时打开MessagesActivy。

目前,当我点击通知时会打开SplashActivity(启动活动),当我按下Back按钮时,还会加载MessagesActivity。

我使用自己的ParseBroadCastReciver来处理onPushOpen,在这里你可以看一下代码。

public class MyReciever extends ParsePushBroadcastReceiver {

private static final String TAG = "MyCustomReceiver";
private HashMap<String, String> dataMap;

@Override
protected void onPushOpen(Context context, Intent intent) {
    super.onPushOpen(context, intent);
    if (intent == null) {
        Log.d(TAG, "Receiver intent null");
    } else {
        String action = intent.getAction();
        Log.d(TAG, "got action " + action);
        JSONObject json = null;
        try {
            json = new JSONObject(intent.getExtras().getString("com.parse.Data"));

        } catch (JSONException e) {
            e.printStackTrace();
        }

        Iterator itr = json.keys();
        dataMap = new HashMap<String, String>();
        while (itr.hasNext()) {
            String key = (String) itr.next();
            Log.d(TAG, "key: "+ key);
            try {
                String value = json.getString(key);
                Log.d(TAG, "value: "+value);
                dataMap.put(key, value);

            } catch (JSONException e) {
                e.printStackTrace();
            }
        }

        if(dataMap.containsKey("from")) {
            Log.d("TAG", "key == from i value == "+dataMap.get("from"));
            Intent msgPushIntenet = new Intent(context, MessagesActivity.class);
            msgPushIntenet.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK );
            msgPushIntenet.putExtra("user_id", dataMap.get("from"));
            //msgPushIntenet.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
            context.getApplicationContext().startActivity(msgPushIntenet);
            Log.d("TAG", "startujem Messages Activity");
        }


    }
}

}

我只能打开 MessagesActivity

1 个答案:

答案 0 :(得分:0)

onPushOpen方法

中使用此功能
 Intent msgPushIntenet = new Intent(context, MessagesActivity.class);
            msgPushIntenet.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK );
            msgPushIntenet.putExtra("user_id", dataMap.get("from"));
            context.startActivity(msgPushIntenet);

来自here