我正在使用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 ?
答案 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。