另一个附带的问题是,如果上下文已经是应用程序上下文,我想是做上下文。getApplicationContext()只会返回自身,对吗?
如果没有区别,它可能只会传入接收器旁边的应用程序,
或者更好的是,它可以在
onReceive(Context context, Intent intent),
然后做上下文。getApplicationContext在那里?
// inside the receiver it will the following with the context:
mContext.bindService(new Intent(mContext, OtherService.class), mInitServiceConnection, Context.BIND_AUTO_CREATE);
mContext.unbindService(mInitServiceConnection);
Intent newStartIntent = new Intent(mContext, InitService.class);
mContext.startService(newStartIntent);
接收器类似于:
class LocalBroadcastReceiver extends BroadcastReceiver {
private final Context mContext;
public LocalBroadcastReceiver(@NonNull Context context) {
mAppContext = context;
}
@Override
public void onReceive(Context context, Intent intent) {
// could it here use the context to get application context, like:
mContext = context.getApplicationContext()
//then do something like:
Intent newStartIntent = new Intent(mContext, InitService.class);
mContext.startService(startMailAccountInitIntent);
}
}