Home > Net >  Is it possible to send a signal from an intent and recover it in another intent
Is it possible to send a signal from an intent and recover it in another intent

Time:04-02

I have 2 activities.. one is launched via deep links. MainActivity doesn't start DeeplinkActivity. How do I know from MainActivity when DeeplinkActivity finishes.

I have tried setting an intent filter programmatically. then added it to MainActivity then in DeeplinkActivity sendBroadcast.

I was unsuccessful since the broadcast recover method in MainActivity wasn't responding to broadcast sent from Deeplink via sendBroadcast(getIntent())

CodePudding user response:

The function you are looking for is putExtra() put this in your FirstActivity :

Intent intent  = new Intent (FirstActivity.this , SecondActivity.class);
intent.putExtra("your key" , yourBooleanVariable) ;
FirstActivity.this.startActivity(intent) ; 

And this code in Your Second Activity :

Intent intent = getIntent() ;
Bundle bundle = intent.getExtras();
if(intent.hasExtra("your key")){
Boolean boolean = bundle.getBoolean();
}

you can put everything in a bundle with putExtra and get it from the bundle in the second Activity

CodePudding user response:

You can use interface, inside onDestroy() of DeepLink activity call the interface method and implement the method in MainActivity. Check this answer. https://stackoverflow.com/a/19027202/7248394

  • Related