Using Application context everywhere?

后端 未结 9 1001
难免孤独
难免孤独 2020-11-22 01:52

In an Android app, is there anything wrong with the following approach:

public class MyApp extends android.app.Application {

    private static MyApp instan         


        
9条回答
  •  耶瑟儿~
    2020-11-22 02:20

    You are trying to create a wrapper to get Application Context and there is a possibility that it might return "null" pointer.

    As per my understanding, I guess its better approach to call- any of the 2 Context.getApplicationContext() or Activity.getApplication().

提交回复
热议问题