2012-06-14 99 views
2

我在我的应用程序中显示一个警告框,以启用GPS,应用程序第一次正常工作,但第二次崩溃,然后适用于第三次罚款和第四次崩溃等上。当崩溃时,显示错误“您的活动正在运行?”。我用处理程序和单独的UI线程尝试过,但没有成功。我正在尝试这个。Android应用程序崩溃时,显示alertBox启用GPS

public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    ExceptionHandler.register(this, WebServiceIface.BASE_URL 
    + "/exception/log"); 
    instanceState = savedInstanceState; 
    appStatus = AppStatus.getInstance(this); 
    appStatus.mFromQrCode = false; 
    mhandler = new Handler(); 
    appPreferences = PreferenceManager.getDefaultSharedPreferences(this); 
    isFromLogin = getIntent().getBooleanExtra("LOGIN_FLAG", false); 
    isOnPause = false; 
    listenForLocation(); 
    loginIfNeeded(); 
} 

private void listenForLocation() { 
    gps = GpsLocator.getGpsLocator(this); 
    gps.listen(); 
} 

@Override 
protected void onResume() { 
    super.onResume(); 
    gps.destroyGpsDialog(); 
    listenForLocation(); 
    compareTimes(); 
    isResuming = true; 
    isOnPause = false; 
    isFromRefresh=true; 
} 

我从GpsLocator活动调用提示框

public void createGpsDialog(){ 

     final AlertDialog.Builder builder = new AlertDialog.Builder(context); 
     builder.setMessage("Yout GPS seems to be disabled, do you want to enable it?").setCancelable(true) 
      .setPositiveButton("Yes", new DialogInterface.OnClickListener() { 
       public void onClick(final DialogInterface dialog, final int id) { 
       dialog.dismiss(); 
        context.startActivityForResult(new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS),6186); 


       } 
      }) 
      .setNegativeButton("No", new DialogInterface.OnClickListener() { 
       public void onClick(final DialogInterface dialog, final int id) { 
        dialog.dismiss(); 
       } 
      }); 
     alert = builder.create(); 
     alert.show(); 
    } 

这是非常奇怪的,它崩溃只在第二次

编辑..

private GpsLocator(CheckinNativeActivity context) { 
     this.context = context; 
     this.observers = new ArrayList<GpsFragment>(); 
     this.removalList = new ArrayList<GpsFragment>(); 
    } 

    public static GpsLocator getGpsLocator(CheckinNativeActivity cxt) { 
     if (ref == null) 
      ref = new GpsLocator(cxt); 
     return ref; 
    } 
+0

什么叫意图上下文传递,你的情况检查任何检查的情况下你有“上下文”变量?你不是在重置它吗? –

+0

这是主要的活动环境,我在这里使用Fragments。 – abhishek

+0

请在此处提供destroyGpsDialog() –

回答

1

在如果要是上下文传递给GPsLocator活动与否而对于活动

+0

我已经传递了上下文。请检查以上,我已添加一个片段。 – abhishek

+0

试试这个,私人GpsLocator(CheckinNativeActivity上下文){this.observers = new ArrayList (); this.removalList = new ArrayList (); } 公共静态GpsLocator getGpsLocator(CheckinNativeActivity CXT){ 如果(参照== NULL) REF =新GpsLocator(CXT); context = cxt; return ref; } – nleshjinde

+0

感谢它的作品........... – abhishek

0

在这里尝试使用context.getApplicationContext()代替cont分机........

Using Application context everywhere?

+0

但是它偶尔会崩溃。即2,4,6 .... – abhishek

+0

不明白?如果应用程序已经崩溃在2,那么你如何达到4? –

+0

当我第一次启动它工作正常,然后我关闭我的应用程序并重新启动它,应用程序崩溃,然后我再次启动我的应用程序它工作正常,然后崩溃时,我重新启动第四次。 – abhishek