1

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())

Bret Joseph
  • 401
  • 3
  • 13

3 Answers3

2

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

Ankit
  • 335
  • 1
  • 10
0

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

0

Both the Model and Broadcast method work.

I chose to use the Broadcast method much simpler

MainActivity

public class MainActivity extends Activity {

    private BroadcastReciever receiver;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        receiver = new BroadcastReceiver() {
            @Override
            public void onReceive(Context p1, Intent p2) {
                // TODO: Implement this method
            }
        };
        registerReceiver(receiver, new IntentFilter(getPackageName() + ".FOO_BAR"));
      
    }

    @Override
    protected void onDestroy()
    {
        super.onDestroy();
        unregisterReceiver(receiver);
    }
}

DeepLink

public class DeepLink extends Activity {
    @Override
    protected void onDestroy()
    {
        super.onDestroy();
        sendBroadcast(new Intent(getPackageName() + ".FOO_BAR"));
    }
}
Bret Joseph
  • 401
  • 3
  • 13