0

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.

Marco
  • 625
  • 3
  • 10
  • 30
  • You probably want a [`Service`](https://developer.android.com/guide/components/services.html), see e.g. [Creating Background Service in Android](http://stackoverflow.com/questions/9177212/creating-background-service-in-android) – dhke Jul 25 '15 at 17:11

1 Answers1

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,

enter image description here

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