Farhan Shah
Farhan Shah

Reputation: 2342

Android when i close my app then How i can restart my app after x time duration?

I am working on Android app which have worked on TV devices,i want when i close my app,and if no one touch the mouse or keyboard,then my app is start automatically after x time duration,this is possible?if yes then please help,Thanks alot.

Upvotes: 0

Views: 231

Answers (3)

Yuvaraja
Yuvaraja

Reputation: 715

Its Possible by using PendingIntent in your service.

http://developer.android.com/reference/android/app/PendingIntent.html

Upvotes: 0

Bhanu Sharma
Bhanu Sharma

Reputation: 5145

Yes it is possible U can take help from service just start one timerthread on Ondestroy() of your app means On last activity or u can perform this action on close of your app. Check with ideal state from thread if any broadcast from mouse or keyboard u will get then reset your timer thread according to it. When ever your timer thread reach at your time just start activity programmatic like

 Intent i = Context.getPackageManager().getLaunchIntentForPackage(Context.getPackageName() );
                i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                i.addCategory(Intent.CATEGORY_HOME);
                i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
                i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                Context.startActivity(i);

Upvotes: 1

kodamirmo
kodamirmo

Reputation: 90

Yes, it is possible, in a Android Service you check if your app is running (check this) if not, you can launch your app. For check user interaction check this

Upvotes: 1

Related Questions