Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There are two kinds of binds you can make local and remote. Local is only for use by your application and remote if for use by any application that implements certain interface. You should start with local binding.</p> <p><a href="http://saigeethamn.blogspot.com/2009/09/android-developer-tutorial-for_04.html" rel="nofollow">Local binding tutorial</a>.<br> <a href="http://www.anddev.org/remote_service_tutorial-t8127.html" rel="nofollow">Remote binding tutorial</a>.</p> <p>My solution without bind:</p> <pre><code>public class MyActivity extends Activity{ @Override public void onCreate(Bundle savedInstanceState){ ... Intent it = new Intent(MyService.ACTIVITY_START_APP); it.setClass(getApplicationContext(), MyService.class); startService(it); } ... @Override protected void onResume() { super.onResume(); registerBroadcastReceiver(); } @Override protected void onPause() { super.onPause(); this.unregisterReceiver(this.receiver); } ... private BroadcastReceiver receiver = new BroadcastReceiver(){ @Override public void onReceive(Context context, Intent intent) { if (intent.getAction().equals(MyService.BROADCAST_INIT)) { //do your stuff here after init } } }; private void registerBroadcastReceiver(){ IntentFilter filter = new IntentFilter(); filter.addAction(HMyService.BROADCAST_INIT); this.registerReceiver(receiver, filter); } } </code></pre> <p>Your service:</p> <pre><code>public class MyService extends Service{ public static final String BROADCAST_INITIAL_DATA = "org.myapp.BROADCAST_INIT"; public static final String ACTIVITY_START_APP = "org.myapp.ACTIVITY_START_APP"; @Override public int onStartCommand (Intent intent, int flags, int startId){ super.onStartCommand(intent, flags, startId); if(intent.getAction().equals(ACTIVITY_START_APP)){ //do your initialization //inform the client/GUI Intent i = new Intent(); i.setAction(BROADCAST_INIT); sendBroadcast(i); }else{ //some other stuff like handle buttons } } } </code></pre> <p>good luck.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload