@falcon_sapsan
DevOps

Почему Intent возвращает null?

public class RepeatingAlarmService extends BroadcastReceiver {
.............
 RemoteViews rViews = new RemoteViews(gcontext.getPackageName(), R.layout.notification_layout);
                rViews.setTextViewText(R.id.textView4, DB.getText());
                Intent buttonsIntent = new Intent(gcontext, NotifyActivityHandler.class);
                buttonsIntent.putExtra("do_action2", "yes");
                PendingIntent pApp = PendingIntent.getActivity(gcontext, 4, buttonsIntent, 0);
                rViews.setOnClickPendingIntent(R.id.buttonYes, pApp);

                Intent buttonsIntent2 = new Intent(gcontext, NotifyActivityHandler.class);

                buttonsIntent.putExtra("do_action2", "no");
                PendingIntent pApp2 = PendingIntent.getActivity(gcontext, 5, buttonsIntent2, 0);

                rViews.setOnClickPendingIntent(R.id.buttonNo, pApp2);


                manger = (NotificationManager) gcontext.getSystemService(Context.NOTIFICATION_SERVICE);
                Notification notify = new Notification.Builder(gcontext)
                        .setContentTitle("Напоминалка")
                        .setContentText(DB.getText())
                        .setTicker("Необходимо ответить на вопрос!").setWhen(System.currentTimeMillis() + DB.getServiceRepeatTime()) // java.lang.System.currentTimeMillis()
                        //.setContentIntent()
                        .setDefaults(Notification.DEFAULT_SOUND).setAutoCancel(true)
                        .setSmallIcon(R.drawable.appicon)
                        .setAutoCancel(false)
                        .setContent(rViews)
                        .build();
}


NotifyActivityHandler

public class NotifyActivityHandler extends Activity {

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        String action =  this.getIntent().getExtras().getString("do_action2");
        Log.i("","answer = "+action);  /// здесь NULL

        if (action != null) {
            if (action.equals("yes")) {
               Log.i("", "found (yes)");
            } else if (action.equals("no")) {
                Log.i("", "found  (no)");
            }
        }

        finish();
    }
}


Почему action всегда NULL возвращает? Что не так делаю?
  • Вопрос задан
  • 559 просмотров
Решения вопроса 1
@falcon_sapsan Автор вопроса
DevOps
проблема была в этом месте
PendingIntent pApp = PendingIntent.getActivity(gcontext, 4, buttonsIntent, 0);


Добавил флаг PendingIntent.FLAG_UPDATE_CURRENT
PendingIntent pApp = PendingIntent.getActivity(gcontext, 4, buttonsIntent, PendingIntent.FLAG_UPDATE_CURRENT);
Ответ написан
Комментировать
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы