Android中是否有一种方法相当于ApplicationIDBecomeActive?
我首先尝试使用onStart()或onResume()。然而,使用它们有两个缺点 1、如果我开始另一项活动,然后将其取消,如下所示。(有点像模态显示一个新的viewcontroller,然后将其关闭) onResume()仍将被调用 2、我不能在其他活动中重复使用相同的登录名Android中是否有一种方法相当于ApplicationIDBecomeActive?,android,android-activity,Android,Android Activity,我首先尝试使用onStart()或onResume()。然而,使用它们有两个缺点 1、如果我开始另一项活动,然后将其取消,如下所示。(有点像模态显示一个新的viewcontroller,然后将其关闭) onResume()仍将被调用 2、我不能在其他活动中重复使用相同的登录名 因此,我想知道Android中是否有一种方法与Android中的-(void)application willresignative:(UIApplication*)application完全相同,用于检查用户是否登录,您
因此,我想知道Android中是否有一种方法与Android中的-(void)application willresignative:(UIApplication*)application完全相同,用于检查用户是否登录,您可以在Android中使用。这些类似于iOS中的类。当用户登录后,在sharedPrefs中保存一个布尔值,如果您想再次运行登录过程,请再次进行恢复检查。如果您使用
dismise()
代码将MainActivity
带到前面,您可以在MainActivity.onNewIntent()
中检测到这一点,如下所示:
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
if ((intent & Intent.FLAG_ACTIVITY_REORDER_TO_FRONT) != 0) {
// I've been brought to the FRONT by another activity
}
}
这有用吗?我不能100%确定我是否理解您的要求。您可以使用onRestart()方法。此方法仅在应用程序从后台进入前台时调用
这两种方法的相似性:
它类似于AppDid在“某些情况下”变得活跃。无论何时进入后台,即从活动到主屏幕,都会调用onPause()和onStop()方法。然后在android中恢复到应用程序,然后调用onRestart()和onPause()方法
进入主屏幕时,在iOs中执行生命周期:(应用程序代理生命周期方法)
appWillEnterForeground->appDidBecomeActive
从主屏幕进入前台时Android的生命周期:(活动生命周期方法)
onRestart()->onResume
从上面可以看出,onRestart类似于appWillEnterForeground,onResume类似于appDidBecomeActive;但我们可以使用onRestart而不是onResume作为appDidBecomeActive,因为:
onCreate()->onStart()->onResume()你到底想做什么?答案很容易误导。点击后退按钮将触发上一个活动的onRestart()。根据文档:
在活动停止后调用,在再次启动之前调用。这与UIApplicationIDBecomeActive无关
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
if ((intent & Intent.FLAG_ACTIVITY_REORDER_TO_FRONT) != 0) {
// I've been brought to the FRONT by another activity
}
}