How to use getString() on static String before onCreate()?

前端 未结 5 1533
陌清茗
陌清茗 2020-12-17 10:09

I am trying to use getString() to get an String from resources to assign it to an String array before my activity is created:

private static fin         


        
5条回答
  •  余生分开走
    2020-12-17 10:47

    No, you can't use Resources before onCreate(). You can get the instance of Resources in onCreate() by using getResources() where you can get all the Strings. Also the strings are already declared as static by defining them in the strings.xml.

    Pseudo code for accessing the Resources,

    Resources res = getResources();
    String app_name = res.getString(R.string.app_name);
    

提交回复
热议问题