当应用程序被杀死并且服务保持活动状态时如何从广播接收器启动服务。我的广播接收器:
public class NetworkChangeReceiver extends BroadcastReceiver{
@Override
public void onReceive(Context context, Intent intent) {
final ConnectivityManager connMgr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
final android.net.NetworkInfo wifi = connMgr.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
final android.net.NetworkInfo mobile = connMgr.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
Intent intent1 = new Intent(context, ImageUploader.class);
if (wifi != null && wifi.isAvailable()) {
context.startService(intent1);
Toast.makeText(context, "start service execute", Toast.LENGTH_SHORT).show();
} else if(mobile != null && mobile.isAvailable()) {
context.startService(intent1);
}
}
}
当应用程序启动时,一切正常。但是当我杀死应用程序时,我只看到吐司,服务正在睡觉。请帮我!