0

Possible Duplicate:
BroadcastReceivers in ICS

I have a boot receiver that calls an other application on boot received, this worked fine on froyo. but when i tried running it on ICS it does not work and the intent is never called ! This is the Boot Receiver registered in my manifest.

   <receiver android:name=".MyBroadCastReceiver" >
        <intent-filter>
           <action android:name="android.intent.action.BOOT_COMPLETED" />
            <action android:name="android.intent.action.QUICKBOOT_POWERON" />

        </intent-filter>
    </receiver>

This is my Broadcast receiver class

public class MyBroadCastReceiver extends BroadcastReceiver {

@Override
public void onReceive(Context context, Intent intent) {
    // TODO Auto-generated method stub


     if(intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)){
            Intent i = new Intent(context, BootActivity.class);
          i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            context.startActivity(i);


    }else{

    }
}}

why doesnt this work... is there any other way to make it work on ICS??

Community
  • 1
  • 1
Muthumani
  • 115
  • 10
  • This was a security fix in Honeycomb and beyond, see my answer to http://stackoverflow.com/questions/12315325/can-android-application-have-only-broadcast-recevier-and-service-without-activit/12315565#12315565 – NickT Sep 10 '12 at 10:20
  • if tats not possible then is there any other way to get this similar result?? – Muthumani Sep 10 '12 at 11:05

1 Answers1

0

Starting with 3.1 when applications are installed they are in a “stopped” state so they will not be able to run until the user explicitly launches them. Pressing Force Stop will return them to this state.

As a result, when applications are first installed, they are totally ignored by the system until and unless the user manually launches something: clicking on a launcher activity or adding an app widget, most likely.

Developers who had been relying upon getting some sort of system broadcast without user intervention will need to adjust their apps for Android 3.1.

madlymad
  • 6,367
  • 6
  • 37
  • 68
Aditya Nikhade
  • 1,373
  • 10
  • 15
  • You need to manually start the app thru launcher... it is a security fix by the android guys! – Aditya Nikhade Sep 10 '12 at 10:22
  • what i'm actually trying to do is if my app is the present home app on boot up i want the receiver to call tat intent and i managed doin it on an older os. any ideas on how i can accomplish this on ICS? – Muthumani Sep 10 '12 at 11:09
  • Due to security issues... you cant start an intent on boot.... you need to launch it using a launcher... THIS IS ONE OF THE CHANGES DONE IN API VERISONS 3.1 and ABOVE!! – Aditya Nikhade Sep 10 '12 at 11:12
  • 1
    @user1039013: "what i'm actually trying to do is if my app is the present home app on boot up" -- then delete your `BOOT_COMPLETED` `BroadcastReceiver` and make your activity be a home screen. There is a Home sample app in your SDK samples. – CommonsWare Sep 10 '12 at 11:15
  • @CommonsWare i have already done that.it is my home screen app now,but i want a particular intent to take place on system boot up if my app is the home screen app ... – Muthumani Sep 10 '12 at 11:34
  • @AdityaNikhade Thanks for the reply , i understand the security issue,but i want to know if there is an alternate method to do the same operation other than boot receiver? – Muthumani Sep 10 '12 at 11:36
  • 1
    i guess no! But you can launch your receiver thru a dummy activity which registers your receiver and then call finish(); It will look like nothing started but your receiver gets registered! – Aditya Nikhade Sep 10 '12 at 11:37
  • 1
    @user1039013: "i want a particular intent to take place on system boot up if my app is the home screen app" -- then have the home screen activity do that work when it appears. Otherwise, you will have to wait until the user does one of the things listed in this answer before your `BOOT_COMPLETED` `BroadcastReceiver` will be able to work. – CommonsWare Sep 10 '12 at 11:45
  • `@Override public Intent registerReceiver(BroadcastReceiver receiver, IntentFilter filter) { filter.addAction("BOOT_COMPLETED"); receiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { // if(MyApplication.isActivityVisible() == true){ if(intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)){ Intent i = new Intent(context, BootActivity.class); i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(i); } }else{} } }; return super.registerReceiver(receiver, filter); } ` – Muthumani Sep 11 '12 at 10:02
  • i registered the receiver like this in my home app in the main activity yet i do not receive the boot complete action... – Muthumani Sep 11 '12 at 10:07
  • 1
    missed this one :) now its working – Muthumani Sep 12 '12 at 12:17