从外部应用程序返回时出现黑屏

发布于 2024-12-29 06:39:57 字数 930 浏览 1 评论 0原文

我有一个应用程序可以打开外部应用程序来读取 PDF 文件。这是打开外部应用程序的代码。

        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 reader 应用程序)返回时,第一次单击后退按钮时,我会看到黑屏,然后我可以访问我的活动吗?我怎样才能解决这个问题?

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();
        }
        }

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

清风不识月 2025-01-05 06:39:57

我认为这可能是正常的 Activity 生命周期。

一旦您的 Activity 进入后台,操作系统就会认为它不再重要,并且它的进程可能会被终止,以便为前台 Activity 回收内存或资源。按下后退按钮时看到的黑屏是应用程序主题的窗口背景,在重新创建 Activity 并恢复其状态时出现。

这是正常行为。通过实施适当的生命周期方法来减少重新创建所需的时间,确保您的 Activity 有效地保存和恢复其状态。

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

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

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.

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.

See http://developer.android.com/reference/android/app/Activity.html#ActivityLifecycle

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文