How-to start service automatically on system startup and on installation

by Ralf » Mon, 13 Apr 2009 13:08:20 GMT


Sponsored Links
 All you need is to create a BroadcastReceiver that is bound to the
BOOT_COMPLETED action.

Tout ce que tu as a faire c'est de creer un BroadcastReceiver qui
recoit l'action BOOT_COMPLETED (avec la permission qui va bien).

Exemple:

<manifest xmlns:android=" http://schemas.android.com/apk/res/android" ;
package="com.alfray.timeriffic" ...>
  <application ...>
    <receiver android:name=".MyBroadcastReceiver">
      <intent-filter>
        <action android:name="android.intent.action.BOOT_COMPLETED" />
      </intent-filter>
    </receiver>
  </application>

<!-- Important -->
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
</manifest>

R/





--~--~---------~--~----~------------~-------~--~----~



Other Threads

1. Fwd: Problem in Handler

plz tell ,me how to handle key dispatch timed out error in android. I have
developed a small quiz application. If i double click my app two times then
it shows *key dispatch timed out error* .
Plz help me if any one knows

---------- Forwarded message ----------
From: yogi <yogi.ru...@gmail.com>
Date: Thu, Feb 3, 2011 at 9:46 AM
Subject: [android-developers] Problem in Handler
To: Android Developers <android-developers@googlegroups.com>


Hi all,
I have created to thread in an application, and from these threads i
am sending a value.
But the App has started but after 5-6 seconds it crashes and with the
following log error.


02-03 09:40:19.598: ERROR/AndroidRuntime(1684): FATAL EXCEPTION: main
02-03 09:40:19.598: ERROR/AndroidRuntime(1684):
android.util.AndroidRuntimeException: { what=1000 when=2469427 obj=4 }
This message is already in use.
02-03 09:40:19.598: ERROR/AndroidRuntime(1684):     at
android.os.MessageQueue.enqueueMessage(MessageQueue.java:171)
02-03 09:40:19.598: ERROR/AndroidRuntime(1684):     at
android.os.Handler.sendMessageAtTime(Handler.java:457)
02-03 09:40:19.598: ERROR/AndroidRuntime(1684):     at
android.os.Handler.sendMessageDelayed(Handler.java:430)
02-03 09:40:19.598: ERROR/AndroidRuntime(1684):     at
android.os.Handler.sendEmptyMessageDelayed(Handler.java:394)
02-03 09:40:19.598: ERROR/AndroidRuntime(1684):     at
android.os.Handler.sendEmptyMessage(Handler.java:379)
02-03 09:40:19.598: ERROR/AndroidRuntime(1684):     at
android.view.ViewRoot.scheduleTraversals(ViewRoot.java:652)
02-03 09:40:19.598: ERROR/AndroidRuntime(1684):     at
android.view.ViewRoot.requestLayout(ViewRoot.java:596)
02-03 09:40:19.598: ERROR/AndroidRuntime(1684):     at
android.view.View.requestLayout(View.java:8125)
02-03 09:40:19.598: ERROR/AndroidRuntime(1684):     at
android.view.View.requestLayout(View.java:8125)
02-03 09:40:19.598: ERROR/AndroidRuntime(1684):     at
android.view.View.requestLayout(View.java:8125)
02-03 09:40:19.598: ERROR/AndroidRuntime(1684):     at
android.view.View.requestLayout(View.java:8125)
02-03 09:40:19.598: ERROR/AndroidRuntime(1684):     at
android.view.View.requestLayout(View.java:8125)
02-03 09:40:19.598: ERROR/AndroidRuntime(1684):     at
android.widget.TextView.checkForRelayout(TextView.java:5378)
02-03 09:40:19.598: ERROR/AndroidRuntime(1684):     at
android.widget.TextView.setText(TextView.java:2688)
02-03 09:40:19.598: ERROR/AndroidRuntime(1684):     at
android.widget.TextView.setText(TextView.java:2556)
02-03 09:40:19.598: ERROR/AndroidRuntime(1684):     at
android.widget.TextView.setText(TextView.java:2531)
02-03 09:40:19.598: ERROR/AndroidRuntime(1684):     at
com.demo.app.handlerapp$3.handleMessage(handlerapp.java:95)
02-03 09:40:19.598: ERROR/AndroidRuntime(1684):     at
android.os.Handler.dispatchMessage(Handler.java:99)

Please refer to the following code which i have written.

package com.demo.app;

import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

public class handlerapp extends Activity implements OnClickListener{
   /** Called when the activity is first created. */
       @Override
   public void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.main);
       button=(Button)findViewById(R.id.Button01);
       tw=(TextView)findViewById(R.id.TextView01);
       tw.setText("click button to start");
       button.setOnClickListener(this);
  }
       @Override
       public void onClick(View v) {
               // TODO Auto-generated method stub
       switch(v.getId()){
       case R.id.Button01:
               Toast.makeText(getApplicationContext(), "clicked", 2).show();
               if(!th.isAlive())
           th.start();
               if(!th1.isAlive())
                       th1.start();
               break;
       }

       }
       Thread th= new Thread(new Runnable(){

               @Override
               public void run() {
                       // TODO Auto-generated method stub
                       Message msg= handler.obtainMessage();
                       for(int i=2;i<1000;i++)
                       {
                               try {
                                       Thread.sleep(5000);
                               } catch (InterruptedException e) {
                                       // TODO Auto-generated catch block
                                       e.printStackTrace();
                               }
                       msg.obj= i;
                       msg.what=2;
                       handler.sendMessage(msg);
                       }

               }

       });
       Thread th1= new Thread(new Runnable(){
               @Override
               public void run() {
                       // TODO Auto-generated method stub
                       Message msg= handler.obtainMessage();
                       for(int i=2;i<1000;i++)
                       {
                               try {
                                       Thread.sleep(3000);
                               } catch (InterruptedException e) {
                                       // TODO Auto-generated catch block
                                       e.printStackTrace();
                               }
                       msg.obj= i;
                       msg.what=1;
                       handler.sendMessage(msg);
                       }

               }

       });

       Handler handler = new Handler(){
               @Override
               public void handleMessage(Message msg) {
                       // TODO Auto-generated method stub
                       super.handleMessage(msg);
                       switch(msg.what){
                       case 1:
                               Toast.makeText(getApplicationContext(),
msg.obj.toString(),
1).show();
                               break;
                       case 2:

                               tw.setText(msg.obj.toString());
                               removeMessages(msg.what, msg.obj);
                       break;
                       }
               }

   };


       Button button;
       TextView tw;
}



Thanks in Advance
Regards
Yogi

--




-- 
Regards,
Roshan

-- 

2. basic problem with the Handler.

Hi All,
I have created a thread in a activity which is sleeping for 1 sec and
then send a message to the main thread using Handler(),
No as the thread start it crashes. with the log as

02-03 09:40:19.598: ERROR/AndroidRuntime(1684):
android.util.AndroidRuntimeException: { what=1000 when=2469427 obj=4 }
This message is already in use.

Did any one have any idea regarding this.

Thanks in Advance
Regards
YOGI

-- 

3. Android copy protection

4. Android-Specific RSS Library

5. BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION intent Extra does not extend 120 sec discovery interval

6. NFC... TAG_DISCOVORED intent is only send via startActivity()

7. How to get application list from android market?