我在我的应用程序中显示警报框以启用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活动调用警告框
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 :(得分:1)
在任何情况下,检查上下文是否通过,在您的情况下检查上下文是否在调用活动意图时传递给GPsLocator活动
答案 1 :(得分:0)
尝试使用context.getApplicationContext()代替上下文........