BroadCastReceiver gives error with BOOT_COMPLETED

0

I need to update the information every 1h and I am using a BroadCastReceiver . If the user opens the APP, it works correctly doing everything every 1h. But I need it to boot the phone and not just when to open the app.

But I do not know why, it says that my application has stopped after the phone calls. I do not know where the error is, since it comes at the end of the methods.

I'm calling AlarmService like this:

public class BootReceiver 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,AlarmReceiver.class);
        i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(i);
    }
}

In my AlarmService is the following code: link

LogCat , I see that it is entering until it reaches the end of the code.

CHEGOU FINAL ANTES abrir arquivo 
CHEGOU FINAL ANTES ESCREVER 
CHEGOU FINAL 

Where could the error be? Thank you in advance for your attention!

    
asked by anonymous 25.06.2016 / 23:32

1 answer

2

Question answered in comments, just moving here.

Change context.startActivity(i) to context.startService(i) .

As for your AlarmReceiver class, I believe you need to update the information to be Service . Then you can use your BootReceiver to start Service when the device boots.

This link will help you with what you need: How to make application running in the background all the time

    
26.06.2016 / 13:29