Note that there are some explanatory texts on larger screens.

plurals
  1. POStarting a service on android platform
    primarykey
    data
    text
    <p>I am starting a service using <strong>startService(Intent intent)</strong> method. When i call this function it reaches the <strong>onCreate</strong> of service but it is unable to call <strong>onStartCommand</strong>. Here is my code--</p> <pre><code>@Override public void onReceive(Context context, Intent intent) { // Send a text notification to the screen. Log.e("mudit", "Action: " + intent.getAction()); try { ConnectivityManager connManager = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo info = connManager.getActiveNetworkInfo(); Log.e("mudit", "getType: " + info.getType()); Log.e("mudit", "isConnected: " + info.isConnected()); if (info.isConnected()) { Intent newinIntent = new Intent(context, service.class); context.startService(newinIntent); } } catch (Exception e) { e.printStackTrace(); Intent newinIntent = new Intent(context, service.class); context.stopService(newinIntent); } } </code></pre> <p><strong>Service Code --</strong> </p> <pre><code>package com.android.service; import android.app.Service; import android.content.Intent; import android.os.IBinder; import android.widget.Toast; public class service extends Service { @Override public IBinder onBind(Intent arg0) { // TODO Auto-generated method stub return null; } @Override public void onCreate() { super.onCreate(); Toast.makeText(this, "Service created...", Toast.LENGTH_LONG).show(); } @Override public void onDestroy() { super.onDestroy(); Toast.makeText(this, "Service destroyed ...", Toast.LENGTH_LONG).show(); } public int onStartCommand(Intent intent, int flags, int startId) { Toast.makeText(this, "onStartCommand...", Toast.LENGTH_LONG).show(); return 1; } } </code></pre> <p><strong>Manifest.xml --</strong></p> <pre><code>&lt;receiver class=".AReceiver" android:name=".AReceiver"&gt; &lt;intent-filter&gt; &lt;action android:name="android.net.conn.CONNECTIVITY_CHANGE" /&gt; &lt;/intent-filter&gt; &lt;/receiver&gt; &lt;service class=".service" android:name=".service" android:enabled="true" android:icon="@drawable/icon"&gt; &lt;/service&gt; </code></pre>
    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.
 

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