开始活动崩溃

时间:2014-05-12 19:20:24

标签: android android-activity

我有位置通知的服务和监听器。 收到位置通知后,我想开始一项活动。 对startActivity的调用每次都会崩溃,我不明白为什么?

我该怎么做?

我的服务:

public class MyService extends Service {
    private Looper mServiceLooper;
    private ServiceHandler mServiceHandler;

    private final class ServiceHandler extends Handler {
        public ServiceHandler(Looper looper) {
          super(looper);
        }
        @Override
        public void handleMessage(Message msg) 
        {
          synchronized (this) 
          {
            Bundle data = msg.getData();
            handleRequest(data);
          }
        }
}

@Override
public void onCreate() {
    HandlerThread thread = new HandlerThread("OpenAppThread");
    thread.start();
    mServiceLooper = thread.getLooper();
    mServiceHandler = new ServiceHandler(mServiceLooper);
...

我的位置通知

public class LocationNotifier implements
    GooglePlayServicesClient.ConnectionCallbacks,
    GooglePlayServicesClient.OnConnectionFailedListener,
    LocationListener {

    private MyService mContext;

public void onLocationChanged(Location locationHere)
{
    Intent intent = new Intent(mContext, AnotherActivity.class);
    mContext.startActivity(intent);  // This Crashes !!!

1 个答案:

答案 0 :(得分:0)

1.-检查您的上下文是否与null不同。 2.-检查您的活动是否已在清单中注册。 3.-检查onLocationChanged是否是一个无限的bucle。

如果您可以复制并粘贴logcat,那么这对我们可以帮助您有用的信息。