简体   繁体   English

当应用程序从 android 的最近列表中删除时,会调用哪个活动?

[英]Which activity is called when app removed from recent list in android?

There are several activities in the android project. android 项目中有几个活动。 But which activity will surely get called when the app is removed from the app list.但是当从应用程序列表中删除应用程序时,肯定会调用哪个活动。

I have checked following questions.我检查了以下问题。 But all these questions are specific to an activity or service但所有这些问题都特定于一项活动或服务

How to handle code when app is killed by swiping in android? 在android中通过滑动杀死应用程序时如何处理代码?

How to detect app removed from the recent list 如何检测从最近列表中删除的应用程序

What method is being called when I close an app 关闭应用程序时调用了什么方法

I also got stuck in very much similar scenario, where I need to trace from which activity the user removed app from recent list, So moving to the point我也陷入了非常相似的场景中,我需要跟踪用户从最近列表中删除了应用程序的哪个活动,所以转到重点

Step 1:第1步:

Create Class ApplicationLifeCycleHandler and implement Application.ActivityLifecycleCallbacks , ComponentCallbacks2 :创建类ApplicationLifeCycleHandler并实现Application.ActivityLifecycleCallbacksComponentCallbacks2

public class ApplicationLifeCycleHandler implements Application.ActivityLifecycleCallbacks, ComponentCallbacks2 {
  private static final String TAG = "AppLifeCycleShareTime";
  private static boolean isInBackground = false;

  @Override
  public void onActivityCreated(Activity activity, Bundle bundle) {
    Log.d( TAG  , "onActivityCreated");
  }

  @Override
  public void onActivityStarted(Activity activity) {
    Log.d( TAG  , "onActivityStarted");
  }

  @Override
  public void onActivityResumed(Activity activity) {
    Log.d(  TAG , "onActivityResumed : " + ShareTime.currentActivity.getClass().getName());
    if(isInBackground){
      Log.d(TAG, "app went to foreground");
      isInBackground = false;
    }
  }

  @Override
  public void onActivityPaused(Activity activity) {
    Log.d(  TAG  , "onActivityPaused : " + activity.getClass().getName());
  }

  @Override
  public void onActivityStopped(Activity activity) {
    Log.d( TAG , "onActivityStopped : " + activity.getClass().getName());
  }

  @Override
  public void onActivitySaveInstanceState(Activity activity, Bundle bundle) {
    Log.d(  TAG  , "onActivitySaveInstanceState");
  }

  @Override
  public void onActivityDestroyed(Activity activity) {
    Log.d( TAG , "onActivityDestroyed Parent : " + activity.getClass().getName());
  }

  @Override
  public void onConfigurationChanged(Configuration configuration) {
    Log.d( TAG , "onConfigurationChanged");
  }

  @Override
  public void onLowMemory() {
    Log.d( TAG , "onLowMemory");
  }

  @Override
  public void onTrimMemory(int i) {
    Log.d( TAG  , "onTrimMemory");
    if(i == ComponentCallbacks2.TRIM_MEMORY_UI_HIDDEN){
      Log.d(TAG, "app went to background");
      isInBackground = true
    }
  }
}

Now: Create Class MyApplication and extend it to Application:现在:创建类MyApplication并将其扩展到应用程序:

public class MyApplication extends Application {
  public static FileMetadata file;

  @Override
  public void onCreate() {
    super.onCreate();
    ApplicationLifeCycleHandler handler = new ApplicationLifeCycleHandler();
    registerActivityLifecycleCallbacks(handler);
    registerComponentCallbacks(handler);
  }
}

Step 3 : Open Manifest File and Add android:name="MyApplication" to application Tag.第 3 步:打开清单文件并将android:name="MyApplication"到应用程序标签。

Step 4 : Check Logs of onActivityDestroyed and you will know the name of activity which is getting destroyed.第 4 步:检查onActivityDestroyed日志,您将知道被销毁的活动的名称。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从最近的应用程序列表中删除应用程序时,将调用哪些生命周期事件? - Which lifecycle events are called when an app is removed from recent apps list? 从Android的“最近列表”中删除应用程序后,如何触发事件 - How to trigger an event, when app is removed from Recent List in Android 从最近列表中刷新应用时,未调用Android Firebase MyFirebaseMessagingService - Android Firebase MyFirebaseMessagingService not called when app is swiped from recent list android中的GCM,当从“设备最近的应用”部分中删除该应用实例时,未显示预期的活动 - GCM in android, not showing the intended activity when the app instance is removed from the Devices RECENT Apps section 从最近的应用程序列表中删除后,Android应用程序进程未终止 - Android app process not killed after removed from recent app list 从最近的应用程序列表中删除应用程序时,BroadcastReceiver无法正常工作 - BroadcastReceiver Not Working When App is removed from recent app list 将应用程序从最近列表中移到前台时,将调用Activity的onDestroy而不是onResume - Activity's onDestroy is called instead of onResume when bringing the app to foreground from recent list 从最近的任务中删除应用程序时,Android 通知被取消 - Android notification gets cancelled when app is removed from recent tasks Android,从“最近的应用”中删除应用时取消通知 - Android, cancel notification when app is removed from “Recent apps” 在android生命周期中,当从最近的应用列表中滑动应用时,是否会调用任何独特的方法? - In android lifecycle, is there any unique method gets called when app is swiped from recent app list?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM