What's the difference between the various methods to get a Context?

前端 未结 8 686
情书的邮戳
情书的邮戳 2020-11-22 04:06

In various bits of Android code I\'ve seen:

 public class MyActivity extends Activity {
    public void method() {
       mContext = this;    // since Activi         


        
8条回答
  •  庸人自扰
    2020-11-22 05:00

    In some cases you may use Activity context over application context when running something in a thread. When thread completes execution and you need to return the result back to the caller activity, you need that context with a handler.

    ((YourActivity) context).yourCallbackMethod(yourResultFromThread, ...);
    

提交回复
热议问题