Stop SMS service if play via SMS is disabled by user

This commit is contained in:
Eric House 2013-04-29 07:40:42 -07:00
parent e4eb867717
commit c8f447171a
2 changed files with 18 additions and 3 deletions

View file

@ -165,6 +165,7 @@ public class PrefsActivity extends PreferenceActivity
if ( sp.getBoolean( key, true ) ) {
SMSService.checkForInvites( this );
} else {
SMSService.stopService( this );
XWPrefs.setHaveCheckedSMS( this, false );
}
} else if ( key.equals( m_downloadPath ) ) {

View file

@ -69,6 +69,7 @@ public class SMSService extends Service {
private static final int MESG_GAMEGONE = 5;
private static final int CHECK_MSGDB = 6;
private static final int ADDED_MISSING = 7;
private static final int STOP_SELF = 8;
private static final String CMD_STR = "CMD";
private static final String BUFFER = "BUFFER";
@ -101,6 +102,12 @@ public class SMSService extends Service {
}
}
public static void stopService( Context context )
{
Intent intent = getIntentTo( context, STOP_SELF );
context.startService( intent );
}
public static void handleFrom( Context context, String buffer,
String phone )
{
@ -226,10 +233,13 @@ public class SMSService extends Service {
@Override
public int onStartCommand( Intent intent, int flags, int startId )
{
int result;
int result = Service.START_NOT_STICKY;
if ( XWApp.SMSSUPPORTED && null != intent ) {
int cmd = intent.getIntExtra( CMD_STR, -1 );
switch( cmd ) {
case STOP_SELF:
stopSelf();
break;
case CHECK_MSGDB:
if ( ! XWPrefs.getHaveCheckedSMS( this ) ) {
XWPrefs.setHaveCheckedSMS( this, true );
@ -283,9 +293,13 @@ public class SMSService extends Service {
}
result = Service.START_STICKY;
} else {
result = Service.START_STICKY_COMPATIBILITY;
}
if ( Service.START_NOT_STICKY == result
|| !XWPrefs.getSMSEnabled( this ) ) {
stopSelf( startId );
}
return result;
} // onStartCommand