D
D
Dmitry2015-09-02 14:08:30
Android
Dmitry, 2015-09-02 14:08:30

Why does Intent return 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();
    }
}

Why does action always return NULL? What am I doing wrong?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry, 2015-09-02
@falcon_sapsan

the problem was in this place
Added flag PendingIntent.FLAG_UPDATE_CURRENT

PendingIntent pApp = PendingIntent.getActivity(gcontext, 4, buttonsIntent, PendingIntent.FLAG_UPDATE_CURRENT);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question