简体   繁体   English

Android开放图库应用

[英]Android open gallery app

I have a button which opens the android gallery app. 我有一个按钮,打开Android图库应用程序。 I use the code 我用的是代码

Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(
 "content://media/internal/images/media")); 
 startActivity(intent); 

for Android>=2.3 found here: Open Gallery App in Android for Android> = 2.3在这里找到: 在Android中打开Gallery App

My problem: When the user opens the gallery from my app and leaves gallery (home button, share image,..), then the gallery will show up next time the user opens my app (without button click). 我的问题:当用户从我的应用程序打开图库并离开图库(主页按钮,共享图像,..)时,该库将在下次用户打开我的应用程序时显示(无需单击按钮)。

How can I avoid the gallery is shown in my app when opening my app? 在打开我的应用程序时,如何避免我的应用程序中显示该库? The gallery should only be shown once when the button is clicked, but not next time my app gets in front. 只有在单击按钮时才会显示一次图库,但下次我的应用程序不在前面时不会显示。

Your best option given what your requirements appear to be is to tell Android not to save the Gallery in your task's history. 根据您的要求,您最好的选择是告诉Android不要将Gallery保存在任务的历史记录中。 That way, when they leave the Gallery activity it will not appear in the task's history stack. 这样,当他们离开Gallery活动时,它将不会出现在任务的历史堆栈中。 Do that by setting a flag on your intent. 通过在您的意图上设置标志来做到这一点。

Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("content://media/internal/images/media")); 
intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
startActivity(intent);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM