我有一個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>
start MainActivity使用意圖 –
使用第二個廣播接收器或本地廣播。 –