1

このようなアクティビティで通知を作成します。

 public static void buildNotification(Context context, int id, String notiContent){
          NotificationManager notificationManager 
          = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
          NotificationCompat.Builder builder = new NotificationCompat.Builder(context);

          Intent intent = new Intent(context, NotifyActivity.class);
          intent.putExtra("notiContent", notiContent);
          intent.putExtra("notiId", id);
          intent.setFlags(Intent.FLAG_ACTIVITY_PREVIOUS_IS_TOP);


          PendingIntent pendingIntent 
          = PendingIntent.getActivity(context, 0, intent, 0);

          builder
          .setSmallIcon(R.drawable.ic_launcher)
          .setContentTitle("")
          .setContentText(notiContent)
          .setContentInfo(""+Math.random())
          .setTicker("!")
          .setLights(0xFFFF0000, 500, 500) //setLights (int argb, int onMs, int offMs)
          .setContentIntent(pendingIntent)
          .setAutoCancel(true);

          Notification notification = builder.build();
          nc++;
          notificationManager.notify(nc, notification);
 }

ただし、onCreateメソッドは常に同じ追加データを取得します ( notiId)。

Intent の再作成を強制する方法は? または、余分なデータをアクティビティに渡す他の方法はありますか?

4

2 に答える 2

1

onResume()メソッドを使用intent.setAction("intentAction");して使用し、それを取得することができますonResume()

于 2012-12-20T13:41:24.130 に答える
0

以下のように更新された値を取得したいアクティビティで使用SharedPreferencesします。onPause()notid

 @Override
protected void onPause() 
{
  super.onPause(); 
  SharedPreferences preferences = getSharedPreferences("sharedPrefs", 0);
  SharedPreferences.Editor editor = preferences.edit();
  editor.putString("notid", "Your notid value"); // value to store
  editor.commit();    
}

以下のように notid の値を取得します。

  SharedPreferences preferences = getSharedPreferences("sharedPrefs", 0);
  String notid= preferences.getString("notid");
于 2012-12-20T13:42:24.220 に答える