Android: Calling non-static methods from a static Handler class

前端 未结 3 402
醉酒成梦
醉酒成梦 2021-02-06 02:47

Given this code:

public class MainActivity extends FragmentActivity implements ActionBar.TabListener {

public static final int MESSAGE_NOT_CONNECTED = 1;

@Over         


        
3条回答
  •  误落风尘
    2021-02-06 03:49

    Since you are now using a WeakReference, mTarget.get() might return null. In your edited code, you are not checking if target is null before executing target.setStatus(R.string.title_not_connected). So this may throw a NullPointerException if the weakreference object has been GC'ed.

提交回复
热议问题