我在我的应用程序中显示一个警报框以启用 GPS,应用程序第一次工作正常,但第二次崩溃,然后第三次正常工作,第四次崩溃,依此类推。崩溃时会显示错误“您的活动正在运行吗?”。我尝试使用处理程序和单独的 UI 线程,但没有成功。我正在尝试这个。
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 Activity 调用警报框
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;
}