2014-03-27 39 views
0

我有一個MainActivity類,它調用服務器來獲取onCreate()方法中的消息。如何重新加載/刷新MainActivity以外的BroadcastReceiver類的主要活動 - Android

然後我在MainActivity類之外有一個BroadcastReceiver類。

這是我的廣播接收器類:

public class GcmBroadcastReceiver extends WakefulBroadcastReceiver { 

@Override 
public void onReceive(Context context, Intent intent) { 
    // Explicitly specify that GcmIntentService will handle the intent. 
    ComponentName comp = new ComponentName(context.getPackageName(), 
      GcmIntentService.class.getName()); 
    // Start the service, keeping the device awake while it is launching. 
    startWakefulService(context, (intent.setComponent(comp))); 
    setResultCode(Activity.RESULT_OK); 

    Bundle extras = intent.getExtras(); 

    if (extras != null) { 

     // This is where I want to refresh/reload MainActivity 

    } 

} 

}

如果額外= NULL我想刷新我的MainActivity類別,以便它的的onCreate()再次調用。我怎樣才能做到這一點?

這是我的清單文件片段:

<receiver 
    android:name="za.co.vine.samplepush.GcmBroadcastReceiver" 
    android:permission="com.google.android.c2dm.permission.SEND" > 
    <intent-filter> 

     <!-- Receives the actual messages. --> 
     <action android:name="com.google.android.c2dm.intent.RECEIVE" /> 

     <category android:name="za.co.vine.samplepush" /> 
    </intent-filter> 
</receiver> 
+0

start MainActivity使用意圖 –

+0

使用第二個廣播接收器或本地廣播。 –

回答

0

使用意圖啓動MainActivity,我會改的android:launchMode屬性爲「singleTop」,讓你沒有你2個實例MainActivity

+0

如何從位於MainActivity類之外的BroadcastReceiver類調用該類? – lulu88

+1

madhu的回答可能是好的。我會將android:launchMode屬性更改爲「singleTop」,以便您沒有2個主體活動MainActivity – kmdupr33

+0

非常感謝!添加它作爲答案或編輯上面,我會接受它? – lulu88

相關問題