I'm trying to send the intent.putString to other class but it's not working I don't know why
trigger.setOnClickListener( v-> {
Bundle bundle = new Bundle();
bundle.putString("params", "okay");
Intent intent = new Intent(this, MainActivity.class);
intent.putExtras(bundle);
//finishAffinity();
startActivityForResult(intent,0);
});
when the button clicked I send bundle to mainActivity
and I get message from mainactivity oncreate.
Bundle extras = this.getIntent().getExtras();
if(extras != null ) {
String _getData = extras.getString("param1");
Log.i(TAG, "face detect message " _getData);
}
but I can't get any message on MainActivity. plz give me some answer
CodePudding user response:
You should aware that bundle is using key value pair, so if you create
bundle.putString("params", "okay");
the key is params
and value is okay
And to get the value you should use the same key.
String _getData = extras.getString("params");
CodePudding user response:
you have to change your params key in the Bundle. Like Below
Bundle extras = this.getIntent().getExtras();
if(extras != null ) {
String _getData = extras.getString("params");
Log.i(TAG, "face detect message " _getData);
}