从外部应用程序返回时出现黑屏
我有一个应用程序可以打开外部应用程序来读取 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为这可能是正常的 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