2

Possible Duplicate:
Use of Context to start another Activity

I am starting activity by "startActivity(new Intent(aContext,class))" method in a class which is inherited by Activity class.

My question is: what is the first parameter of Intent's constructor either Application Context or Activity Context? Please explain . What is the memory issue by using either of these?

When use application context and when activity context? Please explain with a simple example.

Community
  • 1
  • 1
user1041858
  • 947
  • 2
  • 15
  • 32

1 Answers1

2

yes there are memory issues please refer the developers site bellow to understand the issue better

if you use activity context to refer to something out of the scope of the activity the garbage collector wont be able to collect it so the activity will leak memory

as the activity will be destroyed after it finishes if you refer it out of the activity GC wont be able to collect it where as application context have the scope of all the application and wont be needed to be destroyed till app exits

Application context- This context will live as long as your application is alive and does not depend on the activities life cycle. If you plan on keeping long-lived objects that need a context, remember the application object. You can obtain it easily by calling Context.getApplicationContext() or Activity.getApplication(). read this http://android-developers.blogspot.in/2009/01/avoiding-memory-leaks.html

Athul Harikumar
  • 2,501
  • 18
  • 16