I have a situation in my current app where on tapping on a dialog fragment I have to restart the current app in background (or take to home activity) and open calendar app at the same time. I tried firing 2 intents at the same time but it didn't work. I also tried to use AsyncTask's executeOnExecutor
but the order is not always guaranteed. Can someone please explain me how to handle situation like these?
Asked
Active
Viewed 127 times
0

Ari53nN3o
- 1,202
- 2
- 14
- 21
-
http://stackoverflow.com/questions/5034788/how-can-i-open-the-calendar-from-my-app – Anjali Jan 12 '15 at 06:39
-
Thanks for the link @Anjali but opening Calendar isn't an issue for me but restarting the app (or taking to the home activity) in the background is – Ari53nN3o Jan 12 '15 at 06:42
-
what flow exactly you want?? from your application you fire intent of calendar in that case your application is already running in your background. – Anjali Jan 12 '15 at 06:44
-
Yes my app is already running in background when the Calendar is open but with Activity X visible. Now I want the app to go back to Home Activity from Activity X (in the background) while still having Calendar app opened for the user – Ari53nN3o Jan 12 '15 at 06:47
-
You can go to the MainActivity when you return back to your app – Hemanth Jan 12 '15 at 06:51
-
@arol_123 absolutely. But how can we detect return to the app? – Ari53nN3o Jan 12 '15 at 06:52
-
Ah! The `onPause()` and `onResume()` methods – Ari53nN3o Jan 12 '15 at 06:59
1 Answers
1
you have write following code to launch activity first and calendar intent after that:
public void openCalendar(Context mCtx){
Intent activityIntent = new Intent(mCtx, HomeActivity.class);
startActivity(activityIntent );
Intent i = new Intent();
//Froyo or greater (mind you I just tested this on CM7 and the less than froyo one worked so it depends on the phone...)
cn = new ComponentName("com.google.android.calendar", "com.android.calendar.LaunchActivity");
//less than Froyo
cn = new ComponentName("com.android.calendar", "com.android.calendar.LaunchActivity");
i.setComponent(cn);
startActivity(i);
}

Anjali
- 1
- 1
- 13
- 20
-
Thanks Anjali, that worked! I misread when you first shared the link in the comments – Ari53nN3o Jan 12 '15 at 07:09
-