I'm trying to launch an activity , when i got an incoming call for my android mobile. For that, in ringing state, i started an activity and sets some flags for bring this activity to front. Here is the Code:
Intent intent2open = new Intent(ctx, Main.class);
intent2open.setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT | Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_PREVIOUS_IS_TOP);
intent2open.setAction("android.intent.action.VIEW");
intent2open.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent2open.setAction(Intent.ACTION_MAIN);
intent2open.addCategory(Intent.CATEGORY_LAUNCHER);
intent2open.putExtra(name, value);
startActivity(intent2open);
By using above code, i didnt get my required output, some cases app will be launched when i accepted or rejected my call. In some other cases,it will be launched when the state in ringing. I am unable to addressed this issue.. How can i bring my activity to front.
Thanks in advance, Lokesh.
Set android:launchMode="singleTop"
to your activity in manifest and set your flags as:
intent2open.setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT
|Intent.FLAG_ACTIVITY_REORDER_TO_FRONT
|Intent.FLAG_ACTIVITY_NEW_TASK);
* at least it works well for me in my project
Update
Increase of priority in manifest for your broadcast's intent-filter may also help you in this case:
<!-- Higher numbers have a higher priority -->
<intent-filter android:priority="100">
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.