Firebase Cloud Messaging (FCM) - Launch Activity when user clicks the notification with extras

前端 未结 2 1913
死守一世寂寞
死守一世寂寞 2020-12-13 02:56

I\'m trying to open a specific activity when the user clicks the notification, when the app is in the background, with some extra parameters. I\'m using the click_acti

2条回答
  •  感情败类
    2020-12-13 03:33

    Add addition information to Intent that you use to start Activity, and in activity in method onCreate use getIntent().getExtras() to use them. For example:

    Starting activity:

    Intent intent = new Intent(context, TargetActivity.class);
    Bundle bundle = new Bundle();
    bundle.putString("extraName", "extraValue"); 
    intent.putExtras(bundle);
    startActivity(intent); 
    

    In activity

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    
        Bundle bundle = getIntent().getExtras();
        String value = bundle.getString("extraName");
        ....
    }
    

提交回复
热议问题