關於百度雲推送點擊通知的跳轉問題

問題描述:在onNotificationClicked中設置Intent跳轉後並不能跳轉到相應的Activity中,而是直接重新啓動應用,從啓動頁開始加載

解答:
自定義的內容 Intent intent = new Intent(context.getApplicationContext(), C_PasswordActivity.class);

自定義的內容 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”

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章