问题描述:在onNotificationClicked中设置Intent跳转后并不能跳转到相应的Activity中,而是直接重新启动应用,从启动页开始加载
解答:
自定义的内容 Intent intent = new Intent(context.getApplicationContext(), C_PasswordActivity.class);
具体代码:
/**
* 接收通知点击的函数。
*
* @param context
* 上下文
* @param title
* 推送的通知的标题
* @param description
* 推送的通知的描述
* @param customContentString
* 自定义内容,为空或者json字符串
*/
@Override
public void onNotificationClicked(Context context, String title,
String description, String customContentString) {
String notifyString = "通知点击 title=\"" + title + "\" description=\""
+ description + "\" customContent=" + customContentString;
Log.d(TAG, notifyString);
// 自定义内容获取方式,mykey和myvalue对应通知推送时自定义内容中设置的键和值
if (!TextUtils.isEmpty(customContentString)) {
JSONObject customJson = null;
try {
customJson = new JSONObject(customContentString);
String myvalue = null;
if (!customJson.isNull("mykey")) {
myvalue = customJson.getString("mykey");
}
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
// // Demo更新界面展示代码,应用请在这里加入自己的处理逻辑
updateContent(context, notifyString);
}
private void updateContent(Context context, String content) {
Log.i("-hicore-", "updateContent");
String logText = "" + Push_Utils.logStringCache;
if (!logText.equals("")) {
logText += "\n";
}
SimpleDateFormat sDateFormat = new SimpleDateFormat("HH-mm-ss");
logText += sDateFormat.format(new Date()) + ": ";
logText += content;
Push_Utils.logStringCache = logText;
Intent intent = new Intent();
intent.setClass(context.getApplicationContext(), C_PasswordActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.getApplicationContext().startActivity(intent);
}
若是会出现出现两个相同的Activity 则在声明中设置一下android:launchMode=”singleTask”