0

So I want when my push notifications was received and user clicked it, I want to send some data to activity, so that it won't be reopened again, I've tried to send broadcast, but broadcast is not receiving data for some reason.

if(!MainActivity.mStarted) {
        contentIntent = PendingIntent.getActivity(this, 0,
                new Intent(this, MainActivity.class).putExtra("push", "true"), PendingIntent.FLAG_UPDATE_CURRENT);
    } else {
        contentIntent = PendingIntent.getBroadcast(this, 0,
                new Intent(this, MainActivity.class).putExtra("push", "true")
                        .setAction(ACTION_RECEIVED),PendingIntent.FLAG_NO_CREATE);
    }

And in activity:

    @Override
protected void onResume() {
    super.onResume();

    myBroadcastReceiver = new MyBroadcastReceiver();

    IntentFilter intentFilter = new IntentFilter(
            GcmIntentService.ACTION_RECEIVED);
    intentFilter.addCategory(Intent.CATEGORY_DEFAULT);
    registerReceiver(myBroadcastReceiver, intentFilter);

    final OrdersFragment fragment = (OrdersFragment) getFragmentManager().findFragmentByTag(ORDERS_TAG);
}

public class MyBroadcastReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        Log.e("GOT", "SOMETHING");
    }
}

Maybe I'm doing something wrong, then how can I perform my activity to update, and not reopen itself?

P.S. could you please instead of placing a minus for question make a normal reply of how can I improve my code or improve my question?

k.nadonenko
  • 628
  • 2
  • 7
  • 23

1 Answers1

1

Please, next time searches a little in stackoverflow, because it's possible that other programmer has the same problem and you have a good answer. In your case, you need creates a bundle sytem to send and receive data as in this example.

Tell me if I helped you and good programming!

Community
  • 1
  • 1