新版Android OS(4.4及更高版本)中的"FLAG_ACTIVITY_REORDER_TO_FRONT" [英] 'FLAG_ACTIVITY_REORDER_TO_FRONT' in new flavors of Android OS(4.4 & later)

查看:92
本文介绍了新版Android OS(4.4及更高版本)中的"FLAG_ACTIVITY_REORDER_TO_FRONT"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近,我遇到了重新启动已经在堆栈中的Activity的问题.标志 FLAG_ACTIVITY_REORDER_TO_FRONT 是解决此问题的最佳解决方案.但在Android 4.4及更高版本中后来它不能正常工作(有时活动视图被冻结或应用程序最小化自身,菜单不膨胀以重新启动活动或键盘不允许在文本区域中输入内容),但在以前的版本中,此标志会重新显示-initiate的Activity,并从后堆栈中删除.请查看此链接以了解更多详细信息. >

Recently, I faced a problem to re-initiate Activity that's already in back-stack. The flag FLAG_ACTIVITY_REORDER_TO_FRONT is the best solution for manage this problem. But in Android 4.4 & later it isn't work well(some times Activity view is getting freezes or Application minimizes itself, menu isn't inflated to re-initiated Activity or Keyboard isn't allow to enter something to text area) but in previous versions this flag re-initiate's the Activity, and removed from back stack. Please review this link for more details.

推荐答案

在Android 4.4和更高版本中;稍后,在活动创建"中使用 FLAG_ACTIVITY_REORDER_TO_FRONT 标志时,应用程序行为异常.主要问题是,有时活动"将处于冻结状态,当导航到另一个活动时,键盘无法正常工作(显示了键盘,但用户无法在文本区域输入任何内容),没有为菜单充气或应用程序导航以最小化状态.

In Android 4.4 & later, the application misbehaves when FLAG_ACTIVITY_REORDER_TO_FRONT flag is used in Activity creation. The major issues are, some times Activity is going to freeze state, when navigate to another activity key board isn't working well(key board is shown but user can't enter anything to text area), didn't inflate menu, or Application navigates to minimize state.

我认为此问题与活动的堆栈和流程有关,当启动器活动(在我的应用程序中,SplashScreenActivity是启动器)完成时,则子活动在使用 FLAG_ACTIVITY_REORDER_TO_FRONT时会引起一些问题重新启动以前的活动.因此,在这种情况下,请勿终止启动程序或父级活动&使用startActivityForResult(childAcivityIntent, requestcode)开始下一个活动,&在onActivityResult调用时终止父级活动.另外请记住不要在子&中使用singleInstancesingleTop标志.家长活动.

I think this issue is related to back-stack and flow of activity, when launcher activity(in my application, SplashScreenActivity is a launcher) finishes, then sub-activity causes some problem when using FLAG_ACTIVITY_REORDER_TO_FRONT to re-initiate previous Activity. So in this scenario, don't kill launcher or parent activity & start next activity using startActivityForResult(childAcivityIntent, requestcode), & kill parent activity at the time of onActivityResult call. And also remember don't use singleInstance or singleTop flags in child & parent activities.

private void onStartNextActivity() {
        Intent mIntent= new Intent(SplashscreenActivity.this, ChildActivity.class);
                 mIntent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
       startActivityForResult(mIntent, 1111);
}


@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if(requestCode==1111)
            finish();
}

这篇关于新版Android OS(4.4及更高版本)中的"FLAG_ACTIVITY_REORDER_TO_FRONT"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆