我在我的應用程序中顯示一個警告框,以啓用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;
}
什麼叫意圖上下文傳遞,你的情況檢查任何檢查的情況下你有「上下文」變量?你不是在重置它嗎? –
這是主要的活動環境,我在這裏使用Fragments。 – abhishek
請在此處提供destroyGpsDialog() –