2016-02-16 60 views
0

在我的应用我使用的是后台服务, 这里是应用程序后的基本代码致命信号11(SIGSEGV)码= 2,而使用服务

<application 
     android:allowBackup="true" 
     android:vmSafeMode="true" 
     android:allowClearUserData="true" 
     android:hardwareAccelerated="true" 
     android:largeHeap="true" 
     android:icon="@drawable/ic_launcher" 
     android:label="@string/app_name" 
     android:name=".MyApplication" 
     android:theme="@style/AppTheme" > 


Service contains some timers 


public class ConnectionService extends Service 
{ 
    private final IBinder mBinder = new ConnectionServiceBinder(); 
    private MyApplication app; 

    private CountDownTimer mAliveTimer; 
    public CountDownTimer mPanicTimer; 
    public CountDownTimer mPerodicTimer; 

    /* Not using binder anywhere right now */ 
    public class ConnectionServiceBinder extends Binder 
    { 
     public ConnectionService getService() 
     { 
      return ConnectionService.this; 
     } 
    } 

    @Override 
    public int onStartCommand(Intent intent, int flags, int startId) 
    { 
     //connect(); 
     return START_STICKY; 
    } 

    public void createPerodicTimer() 
    { 
     if (mPerodicTimer != null) 
      mPerodicTimer.cancel(); 

     float fastestInterval = Preferences.getFloatSharedPrefValue(app, Constants.USERDEFAULT_SETTINGS_TIME, 5f) * 60 * 1000; 
     mPerodicTimer = new CountDownTimer((int)fastestInterval, 1000) 
     { 
      @Override 
      public void onTick(long millisUntilFinished) 
      {} 

      @Override 
      public void onFinish() 
      { 
       Location myLocation = app.myLocationProvider.getMyLocation(); 
       Location currentBestLocation = null; 
       String locValue = Preferences.getSharedPrefValue(app, Constants.USERDEFAULT_LOCATION); 
       if (locValue != null) 
       { 
        currentBestLocation = new Gson().fromJson(locValue, Location.class); 
       } 

       if (currentBestLocation == null) 
       { 
        sendPerodicReporting(); 
        Preferences.saveSharedPrefValue(app, Constants.USERDEFAULT_LOCATION , new Gson().toJson(myLocation)); 
       } 
       else 
       { 
        float displacement = Preferences.getFloatSharedPrefValue(app, Constants.USERDEFAULT_SETTINGS_DISTANCE, 50); 
        float dist = myLocation.distanceTo(currentBestLocation); 
        if (dist >= displacement) 
        { 
         sendPerodicReporting(); 
        } 
        else 
        { 
         ApiManager.getInstance().mDbHelper.addToLog("System Event", "Perodic Report not sent", "Distance travelled is less than set displacement settings" + dist + " < " + displacement, app); 
        } 
       } 

       Preferences.saveSharedPrefValue(app, Constants.USERDEFAULT_LOCATION , new Gson().toJson(myLocation)); 
       mPerodicTimer.start(); 
      } 
     }; 

     mPerodicTimer.start(); 
    } 

    @Override 
    public void onCreate() 
    { 
     super.onCreate(); 
     app = (MyApplication) getApplication(); 
     app.mService = this; 
     app.addLocationUpdates(); 
     createPerodicTimer(); 

     mAliveTimer = new CountDownTimer(30000 * 60, 1000) // Keep Alive Timer is 30 minutes 
     { 
      @Override 
      public void onTick(long millisUntilFinished) 
      {} 

      @Override 
      public void onFinish() 
      { 
       if (Preferences.getBoolSharedPrefValue(app.getApplicationContext(), Constants.USERDEFAULT_SETTINGS_ALIVE, false)) 
        sendAliveResponse(); 

       if (Preferences.getBoolSharedPrefValue(app.getApplicationContext(), Constants.USERDEFAULT_IS_PANIC_ENABLED, false)) 
        sendPanicReporting(); 

       mAliveTimer.start(); 
      } 
     }; 

     mPanicTimer = new CountDownTimer(30000, 1000) // Keep Alive Timer is 30 seconds 
     { 
      @Override 
      public void onTick(long millisUntilFinished) 
      {} 

      @Override 
      public void onFinish() 
      { 
       if (Preferences.getBoolSharedPrefValue(app.getApplicationContext(), Constants.USERDEFAULT_IS_PANIC_ENABLED, false)) 
       { 
        sendPanicReporting(); 
        mPanicTimer.start(); 
       } 
      } 
     }; 

     mAliveTimer.start(); 
    } 

    @Override 
    public void onDestroy() 
    { 
     super.onDestroy(); 
    } 

    @Override 
    public IBinder onBind(Intent arg0) 
    { 
     return mBinder; 
    } 
} 

有时候,我们说以后分钟我得到死机

致命信号11(SIGSEGV)代码= 2 我试过寻找解决方案,但找不到任何工作。

如果我从我的应用程序中删除服务,应用程序工作正常。

我该怎么办才能解决这个错误?

enter image description here

+0

请发布完整的错误和堆栈如果有的话 – SagiLow

+0

@SagiLow请检查 –

+0

没有更多信息?你有没有尝试添加一些日志打印,看看它发生了什么? – SagiLow

回答

0

我不知道(这是一个有点难以弄清楚发生了什么不完整的堆栈跟踪),但尝试禁用的服务共享偏好的储蓄和检查,如果应用程序失败。我认为这个问题可能是由Gson序列化产生的字符串造成的。

我检查实施JsonElement的返回一行

new Gson().toJson(...) 

,似乎还没有实现了java.io.Serializable接口。这可能在对象保存期间导致问题。

+0

是的,这正是问题所在,我之前修复过这个问题,但是对于任何人的未来引用:)。它工作,如果我调试但不知道为什么有时它失败 –

相关问题