Android get activity from within anonymous class

前端 未结 2 2117
南方客
南方客 2020-12-17 19:00

I\'m super new to Android development and Java in general. Here\'s the basic setup: I have a splash screen with an AsyncTask to check server availability. Follo

相关标签:
2条回答
  • 2020-12-17 19:15

    If The activity that you use Called "MyActivity" then you can do the following:

    MyActivity.this
    

    This chunk of code will return the this "current" object of outer class

    0 讨论(0)
  • 2020-12-17 19:21

    Use CurrentClassName.this

    Intent i = new Intent(CurrentClassName.this, LoginActivity.class);
    

    getActivity(): used with Fragments

    Return the Activity this fragment is currently associated with.

    class.this isn't the same as this when you have nested class.

    0 讨论(0)
提交回复
热议问题