2014-06-27 56 views
0

我在Android上解析通知時出現了一個奇怪的問題。Android活動沒有從解析通知入門

它只發生在應用程序未運行,收到通知並啓動應用程序的情況下。第一個通知將正確啓動默認推回調活動,但是後續任何通知都不會啓動活動!這使得通知無法檢測。

當應用程序從它的圖標啓動時,回調活動正確啓動,我看到了調用的onCreate函數。但是,當它從圖標啓動時失敗。

我已經正確添加了所有權限和應用程序清單添加。我將以下類指定爲初始化Parse API並設置回調的應用程序。

package com.distriqt.example.test; 

import android.app.Application; 
import com.parse.Parse; 
import com.parse.ParseInstallation; 
import com.parse.PushService; 

public class MainApplication extends Application 
{ 
    public static String PARSE_APPLICATION_ID = "XXXX"; 
    public static String PARSE_CLIENT_KEY  = "YYYY"; 

    @Override 
    public void onCreate() 
    { 
     super.onCreate(); 

     Parse.setLogLevel(Parse.LOG_LEVEL_DEBUG); 

     Parse.initialize(this, PARSE_APPLICATION_ID, PARSE_CLIENT_KEY); 
     PushService.setDefaultPushCallback(this, ParseCallbackActivity.class); 
     ParseInstallation.getCurrentInstallation().saveInBackground(); 
    } 
} 

我的回調活動如下所示。我基本上開始了主要的活動,我在這裏做了一些關於通知的處理,然後立即完成活動。

package com.distriqt.example.test; 

import android.app.Activity; 
import android.content.Intent; 
import android.content.pm.PackageManager; 
import android.os.Bundle; 
import android.util.Log; 

public class ParseCallbackActivity extends Activity 
{ 
    public static String TAG = ParseCallbackActivity.class.getSimpleName(); 

    @Override 
    public void onCreate(Bundle savedInstanceState) 
    { 
     super.onCreate(savedInstanceState); 
     Log.d(TAG, "onCreate()"); 

     PackageManager pm = getPackageManager(); 
     Intent mainAppIntent = pm.getLaunchIntentForPackage(getPackageName()); 
     mainAppIntent.putExtras(getIntent().getExtras()); 
     mainAppIntent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); 
     startActivity(mainAppIntent); 

     printIntent(getIntent()); 

     finish(); 
    } 
    public static void printIntent(Intent intent) 
    { 
     try 
     { 
      Log.d(TAG, "action = " + intent.getAction()); 
      if (intent.getExtras() != null) 
      { 
       String channel = intent.getExtras().getString("com.parse.Channel"); 
       JSONObject json = new JSONObject(intent.getExtras().getString("com.parse.Data")); 


       Log.d(TAG, "=============================================="); 
       Log.d(TAG, String.format("channel: %s", channel)); 
       Log.d(TAG, String.format("json:  %s", json)); 
       Log.d(TAG, "=============================================="); 
      } 
     } 
     catch (Exception e) 
     { 
     } 
    } 
} 

MainActivity目前只有一個示例佈局。我不知所措...

回答

0

您在AndroidManifest.xml中聲明瞭活動通知嗎?

+0

是的活動是在清單中聲明的​​。 – Michael