0
好吧我有活動,doesent有他的佈局,它只是在那裏採取GPS座標,如果他成功,然後默認相機意圖開始,如果不是我顯示他對話,用戶有2按鈕一個取消並返回到開始活動,第二個是嘗試再次獲取圖片(調用方法獲取gps,然後發送到相機意圖)。showDialog按鈕doesent調用方法我告訴他
的問題是,有時當我打重試按鈕,它doesent調用Getpicture中()methond只是繼續像按鈕從來沒有打,也沒有顯示出對話框,這個問題經常發生
這裏是我的代碼:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getPicture();
}
public void getPicture(){
LocationManager locationManager = null;
locationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
locationListener = new MyLocationListener();
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener);
if(locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)){
if(MyLocationListener.latitude>0){
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(cameraIntent, CAMERA_REQUEST);
} else {
showDialog(GPS_CANT_CONNECT);
}
}else{
showDialog(GPS_OFF);
}
}
@Override
protected Dialog onCreateDialog(int id) {
Dialog d = null;
switch (id){
case GPS_OFF: {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Please turn on your GPS before taking picture");
builder.setNeutralButton("Try Again", new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
getPicture();
}
});
builder.setNegativeButton("Cancel", new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Intent intent = new Intent(StartCameraActivity.this, MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
}
});
d = builder.create();
break;
}
case GPS_CANT_CONNECT: {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("GPS cant get coordinates! Please make sure that you are outside");
builder.setNeutralButton("Try Again", new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
getPicture();
}
});
builder.setNegativeButton("Cancel", new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Intent intent = new Intent(StartCameraActivity.this, MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
}
});
d = builder.create();
break;
}
return d;
}
是didnt RLY幫助。我仍然有問題。但是當我在d.show()返回之前開始工作時,它開始正常工作,但是在我確定問題得到解決之前,不得不測試它一段時間。 – toskebre 2013-04-05 13:27:15
仍然存在問題...我把gps關掉了,所以每次我點擊「再試一次」按鈕時都應該顯示對話框,但它只顯示一次,當我打開它時,它就像我告訴他什麼都不做在onClick方法... – toskebre 2013-04-05 13:29:32
你究竟是什麼意思? – toskebre 2013-04-05 13:35:01