Send application to back & bring to front

[亡魂溺海] 提交于 2019-12-10 17:17:38

问题


I want to develop an application where it will start on particular time & close on particular time. Similar like Alarm but not alarm application. As per my thinking I will start an service when application first started service will check current time & particular timing to match the condition & when condition is to close application it will simply send application to background so that service will be running & when condition for wake up occurs service will bring application front. Is this possible? If yes please give an example links or anything helpful. Also I am trying to understand the service but it's little bit complex for me so if you have link which will help me to understand the service it will be very helpful. Thank You.

Problem Solved:

/*To close the activity/

Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
intent.addCategory(Intent.CATEGORY_DEFAULT);
startActivity(intent);
MainActivity.this.finish();

OR Just finish activity;

MainActivity.this.finish();

/** To start the activity*/

Intent i = new Intent();
i.setAction(Intent.ACTION_MAIN);
i.addCategory(Intent.CATEGORY_LAUNCHER);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
ComponentName cn = new ComponentName(this, MainActivity.class);
i.setComponent(cn);
startActivity(i);

It worked for me still I if any one have better solution please post below.

Thank You


回答1:


You can create a BroadcastReceiver to listen for time changes, and at your specified times, create an Intent to launch or to close your main Activity.



来源:https://stackoverflow.com/questions/6928368/send-application-to-back-bring-to-front

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