私のアプリケーションには2つのアクティビティがあります。"戻るボタン"はアクティビティを終了しません
最初はジオポイントとしてBBDDのアイテムオーバレイプロシージャを持つマップです。このポイントの1つをクリックすると、ユーザに選択されたサイトの名前、説明、写真のみが表示されます。mostrarLugar
アクティビティが表示されます。
私は次の問題があります: 自分のBBDDに10のサイトがある場合、そのうちの1つが表示されているときに戻るボタンをクリックすると、同じリロードのため10回戻るボタンをクリックする必要がありますアクティビティを10回、すべて同じデータで実行します。
問題がどこにあるのかわかりません。
public boolean onKeyDown(int keyCode, KeyEvent event)
を強制終了しようとしていますが、何も起こりません。
問題はonTapメソッドにあると考えられます。ここに私の活動は以下のとおりです。
public class Capas extends ItemizedOverlay<OverlayItem> implements OnGestureListener
private GestureDetector gestureDetector;
Context contexto;
MapView Map;
private ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>();
private final Activity parent;
DataBaseHelper ayudabbdd;
MotionEvent evento;
public Capas(Drawable defaultMarker, Context context, Activity parent)
{
super(boundCenterBottom(defaultMarker));
contexto = context;
gestureDetector = new GestureDetector((OnGestureListener)this);
this.parent = parent;
Map= (MapView) parent.findViewById(R.id.mapaTab);
contexto = parent.getApplicationContext();
}
/****
* Evento que se inicia al tocar
* para detectar el tipo de movimiento
*
*****/
@SuppressWarnings("static-access")
@Override
public boolean onTouchEvent(MotionEvent event, MapView mapView) {
if(this.gestureDetector.onTouchEvent(event))
{
return true; }
else{
evento = event.obtain(event);
Map = mapView;
return super.onTouchEvent(event, mapView);
}
}
public boolean onTap(int index) {
return onTap(index, evento, Map);
}
public boolean onTap(int index,MotionEvent e, MapView map) {
ayudabbdd = new DataBaseHelper(contexto);
ArrayList<Object> datosLugar = ayudabbdd.getLugarPorID(index+1);
//Paso los datos de array a las variables
String nombre = (String) datosLugar.get(1).toString();
muestraElPunto(nombre);
ayudabbdd.close();
return super.onTap(index);
}
そして、これはshowMeSite
活動です。 これはエラーの原因だとは思わないが、私もそれを含めた。
public class mostrarLugar extends Activity{
Context context;
DataBaseHelper ayudabbdd;
int id;
String nombre;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.mostrarlugar);
View nombreDelLugar = (TextView)findViewById(R.id.tnombreLugar);
View descDelLugar = (TextView) findViewById(R.id.tDescLugar);
/********************
* Obtengo los datos del item, con intent procedente
* de otro activity
************************/
String nombreClick = null;
final Bundle extras = getIntent().getExtras();
if(extras!=null){
nombreClick = extras.getString("nombre");
}
//Conectamos a la base de datos y obtenemos el array de datos
ayudabbdd = new DataBaseHelper(this);
ArrayList<Object> datosLugar = ayudabbdd.getLugarPorNombre(nombreClick);
//Paso los datos de array a las variables
nombre = (String) datosLugar.get(1).toString();
String descripcion = (String) datosLugar.get(2).toString();
String foto = (String)datosLugar.get(3).toString();
//Los seteo
((TextView) nombreDelLugar).setText(nombre);
((TextView) descDelLugar).setText(descripcion);
int compienzoBusquedaExtension = foto.length() - 4;
String sFoto;//String del path real de la foto
if(foto.indexOf(".jpg",compienzoBusquedaExtension)!=-1)
sFoto=foto;
else
sFoto=obtenerPatchReal(Uri.parse(foto));
BitmapFactory.Options options=new BitmapFactory.Options();
options.inSampleSize = 5;
Bitmap bitmap = BitmapFactory.decodeFile(sFoto, options);
ImageView iLugar = (ImageView) findViewById(R.id.iDelLugar);
iLugar.setImageBitmap(bitmap);
}
@Override
public void onDestroy()
{
ayudabbdd.close();
super.onDestroy();
}
/*
* Si presiona atras, cerramos la aplicacion
*/
@Override
public boolean onKeyDown(int keyCode, KeyEvent event)
{
if ((keyCode == KeyEvent.KEYCODE_BACK))
{
finish();
}
return super.onKeyDown(keyCode, event);
}
そして、これは私がONTAP方法で使用することをgetLugarPorID
方法で、次のとおりです。
/*********************************************
* Obtener un lugar completo a partir del ID
* @param ID del lugar que queremos saber
* @return Un array con los datos del lugar
***********************************************/
public ArrayList<Object> getLugarPorID(int id)
{
CustomSQLiteOpenHelper helper = new CustomSQLiteOpenHelper(context);
db = helper.getWritableDatabase();
ArrayList<Object> rowArray = new ArrayList<Object>();
Cursor cursor;
try
{
cursor = db.query
(
TABLE_NAME,new String[]{TABLE_ROW_ID, CNOMBRE, CDESC, CFOTO,CLAT,CLONG},TABLE_ROW_ID+"="+id,null, null, null, null, null
);
//movemos el puntero a la primera posicion
cursor.moveToFirst();
// Si hay datos los añado al array que sera devuelto
if (!cursor.isAfterLast())
{
do
{
rowArray.add(cursor.getLong(0));
rowArray.add(cursor.getString(1));
rowArray.add(cursor.getString(2));
rowArray.add(cursor.getString(3));
rowArray.add(cursor.getDouble(4));
rowArray.add(cursor.getDouble(5));
}
while (cursor.moveToNext());
}
cursor.close();
db.close();
return rowArray;
}
catch (SQLException e)
{
Log.e("Error obteniendo datos de lugar", e.toString());
e.printStackTrace();
}
return rowArray;
}
同じ結果のinsted、私はあなたが時間の多くを意味しています何回 – colymore
の同じ活性ロットを示して? –
私はマップの活動にとどまる、これは私の例のマップで4つのintempizedoverlayポイントを描き、私は、そのうちの一つにオープンmostrarLugar.activityをクリックして、正しくサイトを見せて、戻るボタンを押して、再度サイトを私に示して、私はしなければなりません戻るボタンを4回押すと前の動作に戻ります。私はBBDDで10件のサイトを持っている場合は、私は戻って戻ってボタンを10回押すようにしなければなりません。.. acitivty 10倍というlauncheds自分の意思にintent.FLAG_ACTIVITY_CLEAR_TOPを追加してみてください – colymore