Desasignar todos los recursos al pasar de una actividad a otra en android

Does finishing the current activity by calling finish()before stating new intent, deallocate all the resources of the current class?

I am using inputstream in a class(or activity). But without closing the input stream(connection.close()), I am starting a new activity after calling finish()on the present activity. But I am not able get any input stream from the server in the new activity, if the connetion.close() mehod is not called in the previous activity.

Is there any way to deallocate all the resources of the present activity before moving on to a new one(because finish() does not seem to be working).

preguntado el 10 de marzo de 12 a las 04:03

2 Respuestas

The difference is that the activity sees to it that onPause should finish executing first before "destroying" the view, while onStop is a lifecycle stage that follows after the view is already in the background - meaning the activity is not visible anymore.

doing things inside onPause makes sure that the items you need to save are still intact before letting go of them - for example you need to save the text in your EditText, or the on/off position of RadioButtons, etc.

deallocation however doesn't need any of these things anymore, so it should be fine if you do it in your onStop

respondido 11 mar '12, 03:03

:What exactly is the problem with finsh()? - Ashwin

I didn't quite follow your answer. What shoul be done in onStop()? - Ashwin

You shouldn't be keeping things like input streams open longer than the context in which they are needed. If you do find yourself in a situation where you can't clean up after yourself, you puede override finish and do your cleanup there. Just be sure to call super.finish() before you're done.

PS: I am starting a new activity after calling finish()

That's not typical. Usually one would start a new activity and then call finish(). Maybe that's what's biting you.

respondido 11 mar '12, 04:03

I tried calling finish() after starting the new activity. Still the same problem occurs. What exactly does finish() do? Can you give some more details? - Ashwin

I 've read that page before also. It doesn't say anything about deallocating the resources or the inner workings of finish(). On finish() it just reads "Call this when your activity is done and should be closed. The ActivityResult is propagated back to whoever launched you via onActivityResult()." - Ashwin

finish() is last ditch. Manage your lifecycle better. - Pedante

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.