We want to start Notification Activity in FSB app from our app, To doing this we have two different solution:
1. By set component
Intent intent = new Intent(); intent.setComponent(new ComponentName("application-package-name","class-path")); startActivity(intent);
For example FSB application package name is “de.findsomebuddy.app” and Notification Activity class path is “de.findsomebuddy.app.activity.NotificationActivity” so my ComponentName should be like this:
intent.setComponent(new ComponentName("de.findsomebuddy.app","de.findsomebuddy.app.activity.NotificationActivity"));
2. By action name
You should add “intent-filter” for the target Activity (NotificationActivity) in “AndroidManifest.xml” like this:
<activity android:name=".features.main.NotificationActivity"> <intent-filter> <action android:name="action-name" /> <category android:name="android.intent.category.DEFAULT" /> </intent-filter> </activity>
For action name you define, it’s best to use the package name as a prefix to ensure uniqueness. For example, a NOTIFICATION action might be specified as follows:
<action android:name="de.findsomebuddy.app.activity.NOTIFICATION"/>
Intent should be like this:
Intent intent = new Intent("unique-action-name"); intent.putExtra("title", "my custom title"); startActivity(intent);
You can get extra data in target activity like this:
@Override protected void onNewIntent(Intent intent) { super.onNewIntent(intent); String title = intent.getStringExtra("title"); }
Note: Do not use onCreate
method because if your activity’s launchMode was set to singleTop
the onCreate
method will not call if activity is already loaded in memory.