I starting an application from a Wearable Listener, but i don't wanna open the app "visually", keeping it on background. I mean, if the user press the button to see the open apps, he must be able to see this app. How can i do this? I'm not sure if i'm using the correct terms.
Asked
Active
Viewed 74 times
1 Answers
0
You can use IntentService or Service to run any task in background and even without user's interaction. Here goes a sample Service
demo,
public class TestService extends Service {
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
return super.onStartCommand(intent, flags, startId);
}
@Override
public IBinder onBind(Intent arg0) {
return null;
}
}
run the service from a button click,
btnStart.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(MainActivity.this, TestService.class);
i.putExtra("name", "SurvivingwithAndroid");
MainActivity.this.startService(i);
}
});
Which give you the output in console,

Prokash Sarkar
- 11,723
- 1
- 37
- 50
-
But using this method, i will be able to see the running apps, and come back to the UI if i want? – Marco Jul 25 '15 at 17:51
-
Surely you can update the UI when user will open the app. This is just an example. There are tons of possibilities using Service. Google some service example for more information. – Prokash Sarkar Jul 25 '15 at 18:03