AsyncTask and Contexts

后端 未结 5 1416
情书的邮戳
情书的邮戳 2020-12-28 16:59

So I\'m working out my first multi-threaded application using Android with the AsyncTask class. I\'m trying to use it to fire off a Geocoder in a second thread, then update

5条回答
  •  醉酒成梦
    2020-12-28 17:02

    The Context is an object which provides accees to application runtime environment. In most cases when you need to obtain objects from Android environment, such as resources, views, infrastructure classes etc -- you need to have Context in your hands.

    To obtain Context instance is very simple when you're in the Activity class -- Activity itself is a subclass of the Context, so all you need to do -- is to use 'this' keyword to point on your current context.

    Whever you create code which might require Context - you should take care to pass Context object from your parent Activity. In case of your example you could add explicit constructor which accepts Context as input argument.

提交回复
热议问题