fixed OnBoot issue with unintended service starting

This commit is contained in:
Nathan Freitas 2012-02-26 22:47:25 -05:00
parent 36a2348813
commit 697f5aa2f1
1 changed files with 14 additions and 5 deletions

View File

@ -5,6 +5,8 @@ import org.torproject.android.service.TorService;
import android.content.BroadcastReceiver; import android.content.BroadcastReceiver;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
public class OnBootReceiver extends BroadcastReceiver { public class OnBootReceiver extends BroadcastReceiver {
@ -13,6 +15,12 @@ public class OnBootReceiver extends BroadcastReceiver {
if (intent.getAction() != null if (intent.getAction() != null
&& intent.getAction().equals("android.intent.action.BOOT_COMPLETED")) && intent.getAction().equals("android.intent.action.BOOT_COMPLETED"))
{
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean startOnBoot = prefs.getBoolean("pref_start_boot",false);
if (startOnBoot)
{ {
//Phase 1: Launch a service //Phase 1: Launch a service
Intent service = new Intent(); Intent service = new Intent();
@ -20,6 +28,7 @@ public class OnBootReceiver extends BroadcastReceiver {
service.setClass(context, TorService.class); service.setClass(context, TorService.class);
context.startService(service); context.startService(service);
} }
}
} }