Back button from mapView exits application

3863
4
04-01-2015 02:47 PM
MladenSimic
New Contributor

Hi,

I have a problem with activities that contains mapView. When ever activity contains mapView on BACK button pressed instead of finishing only said activity, parent activity is finished too, without explicit finish call.

For example:

Main -> ActivityB (if ActivityB contains mapView on BACK app is closing because BACK on ActivityB closes ActivitB and Main)

Main-> ActivityA -> ActivityB (on BACK on ActivityB closes ActvityB and ActivityA and stays in Main activity).

finish method of any activity is not overridden.

Any suggestions?

0 Kudos
4 Replies
imritanshu
New Contributor III

are u using onBackPressed() method? if yes just call finish() inside this method.

for better solution just paste ur code here.

Thanks

Rhitz

0 Kudos
MladenSimic
New Contributor

Thank you very much for your response Rhitz.

Yes, I am using onBackPressed method. Here is the code:

@Override

public void onBackPressed()

{

     this.finish();

}

Also, in meantime I tried to override finish method:

@Override

public void finish() {

if (this.progressDialog != null && this.progressDialog.isShowing()) {

                                 this.progressDialog.dismiss();

}

if (this.returnGeometryTask != null && this.returnGeometryTask.getStatus() == android.os.AsyncTask.Status.RUNNING) {

                                this.returnGeometryTask.cancel(true);

}

  1. this.mapView.destroyDrawingCache();
  2. super.finish();

}

This makes no difference.

Thanks,Mladen

0 Kudos
lqdeffx
New Contributor II

I would suggest not over-riding the onBackPressed() or finish() unless absolutely necessary.  If your concern is to make sure a background thread is stopped it would be better placed in onStop().  Moving your logic there would always ensure the process is stopped rather than in finish() which may not be called.

Activities | Android Developers

...

Stopped
The activity is completely obscured by another activity (the activity is now in the "background"). A stopped activity is also still alive (the Activity object is retained in memory, it maintains all state and member information, but is not attached to the window manager). However, it is no longer visible to the user and it can be killed by the system when memory is needed elsewhere.

If an activity is paused or stopped, the system can drop it from memory either by asking it to finish (calling its finish() method), or simply killing its process. When the activity is opened again (after being finished or killed), it must be created all over.

0 Kudos
MladenSimic
New Contributor

Thank you for your response,

I did try not overriding finish method, so i moved the code to onDestroy(). This did not make any difference.

What I figured out in the meantime is that this happens only on Samsung Galaxy Trend Plus (GT-S7580)  with 4.2.2 Android version. Further testing on Samsung Galaxy Core Plus (SM-G350) and Galaxy S2 Plus  (GTI-9105P), both with 4.2.2 Android version did not reproduce the issue. However, on GT-S7580 it is 100% repro. Other Android versions on other devices behave normally, including Galaxy Trend Plus (GT-S7580)  with 4.1.2 Android version.

The selected combination of device + Android version is important because our client has a number of devices purchased with a package deal from the provider.

0 Kudos