2017-03-08 3 views

Antwort

0

Verwenden Sie ein BroadcastReceiver:

public class MyBroadcastReceiver extends BroadcastReceiver { 

    @Override 
    public void onReceive(Context context, Intent intent) { 
     final String action = intent.getAction(); 

     // start the SimlessMainService and set an Action Tag 
     Intent yourServiceToHandleThisIntent = new Intent(context, YourServiceToHandleThis.class); 
     if (android.accounts.AccountManager.LOGIN_ACCOUNTS_CHANGED_ACTION.equals(action)) { 
      yourServiceToHandleThisIntent .setAction(Constants.ACTION_LOGIN_ACCOUNTS_CHANGED); 
     } 
     context.startService(yourServiceToHandleThisIntent); 
    } 
} 

Und in der Manifest.xml:

<application> 
... 
    <receiver 
      android:name=".MyBroadcastReceiver " 
      android:enabled="true"> 
      <intent-filter> 
       <action android:name="android.accounts.LOGIN_ACCOUNTS_CHANGED" /> 
      </intent-filter> 
     </receiver> 
... 
</application> 
Verwandte Themen