从外部应用程序回来的时候会出现黑屏应用程序、黑屏、时候

2023-09-12 04:41:12 作者:ℳ๓汐月✾

我有打开外部应用程序阅读PDF文件的应用程序。这里是code打开外部应用程序。

I have an application that open an external application to read PDF files. here is the code to open the external app.

        if(file!=null){
            PackageManager packageManager = getPackageManager();
            Intent testIntent = new Intent(Intent.ACTION_VIEW);
            testIntent.setType("application/pdf");
            List list = packageManager.queryIntentActivities(testIntent, PackageManager.MATCH_DEFAULT_ONLY);
            if (list.size() > 0 && file.isFile()) {
                Intent intent = new Intent();
                intent.setAction(Intent.ACTION_VIEW);
                Uri uri = Uri.fromFile(file);
                intent.setDataAndType(uri, "application/pdf");

                startActivity(intent);
            }else{
            Toast.makeText(this, "problem loading file", Toast.LENGTH_LONG).show();
        }
        }

现在的问题是,当我从我的PDF的应用程序(Adobe Reader或任何PDF阅读器应用程序)回来,在我返回按钮的第一次点击,我得到一个黑色的屏幕,并在第二个我能达到我的活动?我怎么可能解决这个问题?

The problem is when I come back from my pdf application (adobe reader or any pdf reader app), in the first click of my back button I get a black screen and in second I can reach my activity? How could I possibly solve this problem?

推荐答案

我想这可能是在工作正常的活动周期。

I think this is probably the normal Activity lifecycle at work.

在你的活动进入的背景下,它被认为是不再由操作系统至关重要,它的进程可能会以释放内存或资源的前景活动被杀死。黑色的屏幕上,你看到的时候pressing后退按钮是窗口背景应用程序的主题,而你的活动是重新创建,并且其状态恢复时出现。

Once your Activity goes into the background, it is deemed no longer critical by the OS and its process may be killed in order to reclaim memory or resources for a foreground Activity. The black screen you see when pressing the back button is the window background of your application's theme which appears while your Activity is recreated and its state is restored.

这是正常的行为。确保您的活动保存并通过实施适当的生命周期方法,以减少它需要重新创建时间efficently恢复自己的状态。

This is normal behavior. Ensure that your Activity saves and restores its state efficently by implementing the appropriate lifecycle methods to reduce the time it takes to re-create.

请参阅的http://developer.android.com/reference/android/app/Activity.html#ActivityLifecycle