사용하십시오 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);
}
}
그리고 Manifest.xml
의 :
<application>
...
<receiver
android:name=".MyBroadcastReceiver "
android:enabled="true">
<intent-filter>
<action android:name="android.accounts.LOGIN_ACCOUNTS_CHANGED" />
</intent-filter>
</receiver>
...
</application>