当线程退出未捕获的异常时,服务停止工作

时间:2014-11-11 14:07:47

标签: android service destroy

我的活动和活动中有静态值启动服务。在服务中,我检索静态数据。然后,如果我从系统中销毁活动,则静态值在服务中返回null。我的意思是;

public class HomeActivity extends Activity  { 
static String user;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    user="abc";
    Intent serviceint=new Intent(this, PointCheck.class);
    startService(serviceint);
  }
 }

在PointCheck.class中,

public class PointCheck extends Service {
String username;
@Override
public IBinder onBind(Intent intent) {
    return null;
}
@Override
public void onCreate() {
    super.onCreate();
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    username=HomeActivity.user;
    return super.onStartCommand(intent, flags, startId);
}

因此,如果我销毁HomeActivity,logcat会说:“java.lang.IllegalArgumentException:value可能不为null。”

完整日志:

11-11 16:26:11.971: E/AndroidRuntime(22329): FATAL EXCEPTION: main
11-11 16:26:11.971: E/AndroidRuntime(22329): Process: com.hello, PID: 22329
11-11 16:26:11.971: E/AndroidRuntime(22329): java.lang.IllegalArgumentException: value may not be null.
11-11 16:26:11.971: E/AndroidRuntime(22329):    at com.hello.PointCheck$MyLocationListener.onLocationChanged(PointCheck.java:68)
11-11 16:26:11.971: E/AndroidRuntime(22329):    at android.location.LocationManager$ListenerTransport._handleMessage(LocationManager.java:279)
11-11 16:26:11.971: E/AndroidRuntime(22329):    at android.location.LocationManager$ListenerTransport.access$000(LocationManager.java:208)
11-11 16:26:11.971: E/AndroidRuntime(22329):    at android.location.LocationManager$ListenerTransport$1.handleMessage(LocationManager.java:224)
11-11 16:26:11.971: E/AndroidRuntime(22329):    at android.os.Handler.dispatchMessage(Handler.java:102)
11-11 16:26:11.971: E/AndroidRuntime(22329):    at android.os.Looper.loop(Looper.java:157)
11-11 16:26:11.971: E/AndroidRuntime(22329):    at android.app.ActivityThread.main(ActivityThread.java:5872)
11-11 16:26:11.971: E/AndroidRuntime(22329):    at java.lang.reflect.Method.invokeNative(Native Method)
11-11 16:26:11.971: E/AndroidRuntime(22329):    at java.lang.reflect.Method.invoke(Method.java:515)
11-11 16:26:11.971: E/AndroidRuntime(22329):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
11-11 16:26:11.971: E/AndroidRuntime(22329):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:674)
11-11 16:26:11.971: E/AndroidRuntime(22329):    at dalvik.system.NativeStart.main(Native Method)
你怎么了? 感谢

0 个答案:

没有答案