Note that there are some explanatory texts on larger screens.

plurals
  1. POExcellent Service example baffles me
    primarykey
    data
    text
    <p>I'm reading "Pro Android 2" which contains an excellent Service example as follows:</p> <pre><code> import android.app.Service; import android.content.Intent; import android.os.IBinder; import android.util.Log; public class TestService1 extends Service { private static final String TAG = "TestService1"; @Override public void onCreate() { Log.d(TAG, "onCreate"); super.onCreate(); } @Override public IBinder onBind(Intent intent) { Log.d(TAG, "onBind"); return null; } } </code></pre> <p>I also added the service definition entry as a child of:</p> <pre><code> &lt;application&gt; in my AndroidManifest.xml as follows: &lt;service android:name="TestService1"&gt;&lt;/service&gt; </code></pre> <p>The book then says:"The next obvious question is how to do you call the service?"</p> <p>And that's precisely what I want to know!!! I've scoured the book and I don't see how to start up the service. The book actually seems to indicate that the service is called on start up. Maybe I've just misunderstood this part.</p> <p>This is just experimental and I just want to see the service run and see the Log messages in logcat. The book says:"The system calls onCreate() when the service is first created, but before calling onStart(). This process, which resembles the process for creating an activity, provides a way for the service to perform one-time initialization at startup."</p> <p>Well ok, but I'm not sure what to do to start the service except perhaps in my primary activity's onCreate() do something like:</p> <pre><code> Intent TestService1 = new Intent(this,com.mydomain.myproject.TestService1.class); startActivity(TestService1); </code></pre> <p>But when I do this I get THE error: "The application ... has stopped unexpectedly."</p> <p>I think this problem has a simple solution, but I'm just too simple to see it:)</p>
    singulars
    1. This table or related slice is empty.
    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. 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