Android 关于各国活动的澄清

Android 关于各国活动的澄清,android,android-activity,user-experience,Android,Android Activity,User Experience,在我的应用程序中,有几种情况下我应该知道用户可以看到哪些活动 是否有一个函数可以让用户看到当前活动 现在我要做的是创建一个带有静态变量的类,比如 布尔静态mainActivityIsVisible=false 在onResume()和onPause()中在真/假之间切换; 因此,其他活动可以检查此变量以了解情况 Does the same apply to check if an activity is stopped or destroyed ? Or is there a way to

在我的应用程序中,有几种情况下我应该知道用户可以看到哪些活动

  • 是否有一个函数可以让用户看到当前活动
现在我要做的是创建一个带有静态变量的类,比如

布尔静态mainActivityIsVisible=false

在onResume()和onPause()中在真/假之间切换; 因此,其他活动可以检查此变量以了解情况

Does the same apply to check if an activity is stopped or destroyed ? Or is there a way to check the activities from the stack of the app ?
最后

How can I find that the last activity's onDestroy() was called. My objective from this is to find out if the app has totally exited and does not have any activities running, nor is minimized. 
这个问题可以用另一种说法来表达

How can I know my activity is not running."

您可以使用以下选项:

1) 我如何知道活动是否正在运行

class MyActivity extends Activity {
     static boolean active = false;

      @Override
      public void onStart() {
         super.onStart();
         active = true;
      } 

      @Override
      public void onStop() {
         super.onStop();
         active = false;
      }
}
2) 如何检查活动是在前台还是在可见的后台

public class MyApplication extends Application {

  public static boolean isActivityVisible() {
    return activityVisible;
  }  

  public static void activityResumed() {
    activityVisible = true;
  }

  public static void activityPaused() {
    activityVisible = false;
  }

  private static boolean activityVisible;
}
在AndroidManifest.xml中注册应用程序类:

<application
    android:name="your.app.package.MyApplication"
    android:icon="@drawable/icon"
    android:label="@string/app_name" >
在finish()方法中,您希望使用isActivityVisible()检查活动是否可见。在那里,您还可以检查用户是否选择了选项。当两个条件都满足时继续

<application
    android:name="your.app.package.MyApplication"
    android:icon="@drawable/icon"
    android:label="@string/app_name" >
@Override
protected void onResume() {
  super.onResume();
  MyApplication.activityResumed();
}

@Override
protected void onPause() {
  super.onPause();
  MyApplication.activityPaused();
}