1

I'm working on a code as a reference and encountered this Intent call: Intent(getApplicationContext(), secondActivity.class)

I got baffled because in my projects I only use: Intent(".mYSecondActivity")
I tried removing getApplicationContext() and changed it to Intent(".secondActivity")' in which the name is registered in the manifest. I run the application and Forced Closed. What is the significance of getApplicationContext()?

secondActivity.class is coded to retrieve data from a PHP MYSQL database.

droidH
  • 39
  • 1
  • 2
  • 10
  • When you move from one activity to another activity then you have to pass context from 1st activity to 2nd activity because both has different view and 2nd activity must have its own context. – Manish Dubey Feb 21 '13 at 07:12
  • [getApplicationContext()](http://developer.android.com/reference/android/content/Context.html#getApplicationContext()) – Paresh Mayani Feb 21 '13 at 07:14
  • Check provided link in my answer, you'll understand significance of every method of getContext. – Manish Dubey Feb 21 '13 at 07:17
  • I'm having a hard time understanding what context mean. Is it some form of data? @ManishAndroid – droidH Feb 21 '13 at 07:21
  • Context is a kind of base in form of object. It can be a base of application or a base of activity. Everything in android runs according to base. Like if you want to show a dialog so it needs context a base on which that dialog will be shown. so If you are getting application context you get the base of whole application but if you are getting activity context you will get activity base – Abhinav Singh Maurya Feb 21 '13 at 07:25
  • 1
    The answers here are all over the place. If you are starting activities by using `Intent(".mYSecondActivity")` then you must be defining intent-filters for all your activities. This is most probably **not** what you want to be doing. Please post your manifest so we can check this. – David Wasser Feb 21 '13 at 17:34
  • Actually, the significance of `Context` is probably irrelevant to this question. The real question should be: What is the difference between `new Intent("string")` and `new Intent(context, activity.class)` ? and actually, there is a big difference! – David Wasser Feb 21 '13 at 17:39
  • @ David Wasser - here is the manifest ` ` – droidH Feb 22 '13 at 06:50
  • @ David Wasser - I have been searching all night and I can't find a plain explanation in their difference. All I found are code snippets. No explanations. – droidH Feb 22 '13 at 06:52

1 Answers1

0

"This provides a convenient way to create an intent that is intended to execute a hard-coded class name, rather than relying on the system to find an appropriate class for you." source: http://developer.android.com/reference/android/content/Intent.html#Intent%28android.content.Context,%20java.lang.Class%3C?%3E%29

Michał Z.
  • 4,119
  • 1
  • 22
  • 32