Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7028731
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:26:48+00:00 2026-05-28T00:26:48+00:00

I have two activities in my application. The first is a map with item

  • 0

I have two activities in my application.

The first is a map with item overlays proceddents from a BBDD as a geopoints. If I click on one of this points, it shows me the mostrarLugar activity, which only shows the name, a description and a photo of the site that the user had selected.

I have the next problem:
If in my BBDD I have 10 sites, when I’m seeing one of them, if I click the back button, I must to make 10 back button clicks, because app reloads the same activity 10 times, all with the same data.

I don’t have any ideas about where the problem is. I’m trying to force finish with a

  public boolean onKeyDown(int keyCode, KeyEvent event)

but nothing happens.

I think the problem may be in the onTap method. Here are my activities:

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);
    }

And this is the showMeSite activity.
I don’t think this is the source of the error, but I also included it.

   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);
      }

And this is the getLugarPorID method, that I use in the onTap method:

/*********************************************
         * 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;

        }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T00:26:49+00:00Added an answer on May 28, 2026 at 12:26 am

    It should be

    @Override
      public boolean onKeyDown(int keyCode, KeyEvent event)
      {
          if ((keyCode == KeyEvent.KEYCODE_BACK))
          {
              finish();
          return true; // you missed this line
          }
          return super.onKeyDown(keyCode, event);
      }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an Android Honeycomb application with two activities; the first one has a
Ive got two activities in the same application. the first one is with gui(main
I have two different activities. The first launches the second one. In the second
I have an application which consists of two activities/screens and a java class from
I have two activities. The first one executes the second one. Intent i =
I have two activities A and B, and from activity A, I click on
I have two activities in my Android 2.1 application. The first is the Main
In my application I have two activities. In the first activity I have a
Im making a multi activity application and the first two activities i made have
I have here two applications in two different projects in eclipse. One application (A)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.