1
無論何時監聽器收到消息,我都希望將進度和警報對話框添加到活動上下文中。有了這個代碼:來自c2dm偵聽器事件的Tigger alertBox
public class C2DMMessageReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
Log.w("C2DM", "Message Receiver called");
if ("com.google.android.c2dm.intent.RECEIVE".equals(action)) {
Log.w("C2DM", "Received message");
final String payload = intent.getStringExtra("payload");
Log.d("C2DM", "dmControl: payload = " + payload);
// Message handling
if(payload.equals("DataUpdate")) {
progressDialog = ProgressDialog.show(context, "Please wait...", "Synchronizing data ...", true);
syncData(context);
progressDialog.dismiss();
AlertDialog.Builder alertbox = new AlertDialog.Builder(context);
alertbox.setMessage("Data was updated");
alertbox.create();
alertbox.show();
}
}
}
}
我收到以下錯誤,當我收到消息:
01-07 08:44:38.190: E/AndroidRuntime(750): Caused by: android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application
試圖找出什麼是最好的方式來處理,這將是,我需要緩存活動上下文在一個單身人士,然後從聽衆訪問單身人士?或者,還有更好的方法?
感謝
感謝您的鏈接,這有助於清理事情。我要去通知 – Hoofamon 2012-01-07 19:58:04
很高興提供幫助。我非常喜歡Android中的Notification系統,它非常靈活。 – Squonk 2012-01-07 20:08:54