Application should not display in recent app list after finish the activity if app was not displaying recent app list previously

不问归期 提交于 2019-12-04 01:30:50

问题


Step 1- Application is not exist in recent app list (App has been removed from recent app list).
Step 2- As soon as I got notification open IncomingCall activity, User accept the call.
Step 3- User click on disconnect button finish the IncomingCall activity.

Problem- Application showing in recent app list even app was not in recent app list previously.

Manifest entry

<activity
android:name=".activities.IncomingCall"
android:excludeFromRecents="true"
android:launchMode="singleTop"
android:screenOrientation="portrait" >
</activity>

In the activity using

public void onClick(View v) {
switch (v.getId()) {
case R.id.onCallDisconnectButton:
phoneCallBaseClass.disconnect();
IncomingCall.this.finish();
break;
  }
}

And also I have tried below link but it will work when app already exist in background

Remove app from recent apps programmatically

OR Is there any other way to show incoming call view So that it will not persist in history.

you can take example of any VoIP calls app-

Remove app from recent app list after that incoming call came, user disconnect the call activity(IncomingCallActivity) would not be exist in recent app list. But in My case activity persist in recent app list after disconnecting the call.

Thanks


回答1:


Add

android:excludeFromRecents="true" 

to the activity tag of your launcher activity in AndroidManifest.xml file

<activity
    android:name=".MainActivity"
    android:label="@string/app_name"
    android:excludeFromRecents="true">
....
</activity>



回答2:


Thanks God, I got answer after wondering a week. Add singleInstance attribute along with exclude from recent. It was a bug in 5.0 now has been resolved in 5.1

 <activity
        android:name="activityName"
        android:excludeFromRecents="true"
        android:launchMode="singleInstance"
         >
 </activity>



回答3:


As per you needs, finishAndRemoveTask() is the new API that as per the documentation

Finishes all activities in this task and removes it from the recent tasks list.

if(android.os.Build.VERSION.SDK_INT >= 21)
{
    finishAndRemoveTask();
}
else
{
    finish();
}


来源:https://stackoverflow.com/questions/31693570/application-should-not-display-in-recent-app-list-after-finish-the-activity-if-a

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!