We handled the call in a more dynamic way to support any fragment, by having in the Activity
something like:
// ...
public class ActivityMain extends AppCompatActivity {
// ...
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
Fragment fragment = getFragment();
if (fragment != null) {
try {
Method method = fragment.getClass().getMethod("onNewIntent", Intent.class);
method.invoke(fragment, intent);
} catch (NoSuchMethodException ignored) {
} catch (IllegalAccessException | InvocationTargetException e) {
Log.e(TAG, "Failed to call onNewIntent method for class: " + fragment.getClass().getSimpleName());
}
}
}
public Fragment getFragment() {
// For NAVIGATION-DRAWER only
// (replace below logic, if you use View-Pager).
FragmentManager manager = this.getSupportFragmentManager();
manager.executePendingTransactions();
return manager.findFragmentById(R.id.my_main_content);
}
}
Then in each root Fragment
simply listen:
@SuppressWarnings("unused")
public void onNewIntent(Intent intent) {
Log.i("MyTag", "onNewIntent: " + intent);
}
onNewIntent
in Fragment? – Bread