Note that there are some explanatory texts on larger screens.

plurals
  1. POStart Android Service 4.0 boot time
    primarykey
    data
    text
    <p>My English is poor. I cannot start an android service in a boot time and I do not know the problem. I was trying example codes, but without success. Can somebody send me a project in Java that runs? Other code works for other people but on my tablet smartphone emulator it does not work. Does a problem exist in android 4.0?</p> <p>This is my code:</p> <pre><code> &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.service22" android:versionCode="1" android:versionName="1.0" android:installLocation="internalOnly" &gt; &lt;supports-screens android:largeScreens="false" android:normalScreens="true" android:smallScreens="false"/&gt; &lt;uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/&gt; &lt;application android:icon="@drawable/ic_launcher" android:label="@string/app_name"&gt; &lt;service android:name="com.example.MyService"&gt; &lt;intent-filter&gt; &lt;action android:name="com.example.MyService"&gt; &lt;/action&gt; &lt;/intent-filter&gt; &lt;/service&gt; &lt;receiver android:name="com.example.MyReceiver"&gt; &lt;intent-filter&gt; &lt;action android:name="android.intent.action.BOOT_COMPLETED"&gt; &lt;/action&gt; &lt;category android:name="android.intent.category.HOME"&gt; &lt;/category&gt; &lt;/intent-filter&gt; &lt;/receiver&gt; &lt;/application&gt; &lt;/manifest&gt; public class MyService extends Service { private static final String LOG_TAG = "::Monitor"; @Override public void onCreate() { super.onCreate(); Log.e(LOG_TAG, "Service created."); } @Override public void onStart(Intent intent, int startId) { super.onStart(intent, startId); for (int i = 0 ; i &lt; 20 ; i++) { mensaje(); } Log.e(LOG_TAG, "Service started."); } @Override public void onDestroy() { super.onDestroy(); Log.e(LOG_TAG, "Service destroyed."); } @Override public IBinder onBind(Intent intent) { Log.e(LOG_TAG, "Service bind."); return null; } public void mensaje() { Toast.makeText(this, "Hola", Toast.LENGTH_LONG).show(); } } public class MyReceiver extends BroadcastReceiver { public MyReceiver() { } String LOG_TAG = "::StartAtBootServiceReceiver"; @Override public void onReceive(Context context, Intent intent) { Log.e(LOG_TAG, "onReceive:"); if (intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)) { Intent i = new Intent(); i.setAction("com.example.MyService"); context.startService(i); } } } </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.
 

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