How to minimise/hide app programmatically?

折月煮酒 提交于 2021-02-18 22:44:13

问题


I have an activity which is purely transparent (user can't see when it gets open).I open this activity from background service whenever I want to open it. After doing some work, I need to close that activity (not finish()).I want to hide or minimize app. Actually, my app opens up for a second and do someWork after doing someWork, it continues to do remaining work (some uploading process) in background i.e. in onPause.I don't want user to know that something opens & closed immediately.

Currently, I am using below code-

public void minimizeApp() {
 Intent startMain = new Intent(Intent.ACTION_MAIN);
 startMain.addCategory(Intent.CATEGORY_HOME);
 startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
 startActivity(startMain);
}

Now, Problem is that If user is using some other app eg, playing game or using Whatsapp, When my app get opens over previous app(Game or Whatsapp) and minimizeApp() is called then it minimises my app along with other app opened in background. I want to minimize only my app.


回答1:


You can try the following from the activity/context from where you want to minimise the app:

YourActivity.this.moveTaskToBack(true);


来源:https://stackoverflow.com/questions/42068501/how-to-minimise-hide-app-programmatically

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!