中的一個活動我將Intenting通知管理器中的變量作爲第一次意圖成功工作,但第二次當我意圖新消息活動顯示thr perivous值plz幫助我出去im真是一個大問題如何將變量從notificationmanager傳遞給android
這裏是通知管理器的代碼
公共類GCMIntentService擴展GCMBaseIntentService {
私有靜態最後絃樂TAG = 「GCMIntentService」;
公共GCMIntentService(){
super(SENDER_ID);
}
@Override 保護無效onRegistered(上下文語境,字符串registrationId){
Log.i(TAG, "Device registered: regId = " + registrationId); displayMessage(context, "Your device registred with GCM"); Log.d("NAME", MainActivity.name); ServerUtilities.register(context, MainActivity.name, MainActivity.email, registrationId);
}
@Override
保護無效onUnregistered(上下文語境,字符串registrationId){
Log.i(TAG, "Device unregistered"); displayMessage(context, getString(R.string.gcm_unregistered)); ServerUtilities.unregister(context, registrationId);
}
@Override 保護無效的onMessage(上下文範圍內,意圖意圖){
Log.i(TAG, "Received message"); String message = intent.getExtras().getString("price"); displayMessage(context, message); // notifies user generateNotification(context, message);
}
@Override protected void onDeletedMessages(C ontext上下文中,INT總){
Log.i(TAG, "Received deleted messages notification"); String message = getString(R.string.gcm_deleted, total); displayMessage(context, message); // notifies user generateNotification(context, message);
}
@Override 公共無效的onError(上下文語境,字符串ErrorID中){
Log.i(TAG, "Received error: " + errorId); displayMessage(context, getString(R.string.gcm_error, errorId));
}
@覆蓋 保護布爾onRecoverableError(Context context,String errorId){
// log message Log.i(TAG, "Received recoverable error: " + errorId); displayMessage(context, getString(R.string.gcm_recoverable_error, errorId)); return super.onRecoverableError(context, errorId);
}
私有靜態無效generateNotification(上下文語境,字符串消息){
int icon = R.drawable.orange_logo; long when = System.currentTimeMillis(); NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); Notification notification = new Notification(icon, message, when); String title = context.getString(R.string.app_name); Intent notificationIntent = new Intent(context,receivemessage.class); // set intent so it does not start a new activity notificationIntent.putExtra("activate",message.toString()); notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
的PendingIntent意圖= 的PendingIntent。getActivity(context,0,notificationIntent,0);
notification.setLatestEventInfo(context, title, message, contentIntent); notification.flags |= Notification.FLAG_AUTO_CANCEL; // Play default notification sound notification.defaults |= Notification.DEFAULT_SOUND; // Vibrate if vibrate is enabled notification.defaults |= Notification.DEFAULT_VIBRATE; notificationManager.notify(0, notification);
}
}
- 在receivemessage類
公共類receivemessage延伸活動{
TextView textshow;
String saveit;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.message);
textshow=(TextView)findViewById(R.id.showmessage);
Intent i=getIntent();
saveit = i.getStringExtra("run");
textshow.setText(saveit.toString());
}
在此先感謝
好吧,讓我試試這個..... –
它不工作的傢伙....... –
WORKED FOR ME ..... – nobalG