Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Activity Context and Application Context in Android

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 1.39k
    Comment on it

    Below are the differences between Application context and Activity context

    Application context and Activity context are the instances of Context but both of them are tied to different life cycles. Instance of Application context is tied to Application life cycle and gives the context of the entire application where an instance of Activity is tied to Activity life cycle.

    The context of the Activity will not be available after the Activity gets destroyed however the Application context remains available.


    When to use

    Example:- Suppose ProcessDialog is to be shown in an activity, so in this case the activity context will be used as ProcessDialog is attached to that particular activity.

    Activities runs inside of Application, so use Application context only when you want the context of the application and not just the activity.


    How to get the Application context and Activity context

    Application context: getApplicationContext() method is used to get the context of the Application. Activity context: "this" keyword is used to get the context of the Activity.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: