Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion Go To ( http://adf.ly/20PrE )-)-) [android-developers] Re: getString in a class with no context <- Runtime Error Resource Not Found
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Streets Of Boston  
View profile  
 More options Dec 5 2011, 9:30 am
From: Streets Of Boston <flyingdutc...@gmail.com>
Date: Mon, 5 Dec 2011 06:30:13 -0800 (PST)
Local: Mon, Dec 5 2011 9:30 am
Subject: Go To ( http://adf.ly/20PrE )-)-) [android-developers] Re: getString in a class with no context <- Runtime Error Resource Not Found

It's great you got it to work.
But why do you need a separate class (LanguagePack) to get localized
strings/resources?

In a method of your activity or another context, you could just do:
getString(R.string.some_string)?

If you want to access localized resources/strings in code that does not
have a Context readily available, you could create a static singleton of
your LanguagePack class in the Application object of your app:

public class MyApp extends Application {
  private static LanguagePack myLanguagePack = null;

  ...
  ...

  public LanguagePack getLanguagePack() {
    if (myLanguagePack == null) {
      myLanguagePack = new LanguagePack(this);
    }
    return myLanguagePack;
  }
  ...
  ...

}

public class LanguagePack {
  private final Context context;
  public LanguagePack(Context context) {
    this.context = context.getApplicationContext();
  }

  public String getString(int resID) {
    return context.getString(resID);
  }
  ...
  ...

}

And everywhere in your code, you could do
MyApp.getLanguagePack().getString(R.string.some_string);

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

--
Go to Master Mind Home Base Income Website   :-

           http://adf.ly/20PrE

            http://adf.ly/20PrE

Unsubscribe All Group Post :-   http://j.gs/624707/unsubscribe

                                              http://q.gs/624707/unsubscribe

Subscribe All Group Post :-       http://j.gs/624707/subscribe

                                                 http://q.gs/624707/subscribe

Join Now Today (Paid Income) :-

 http://adf.ly/20PrE

http://adf.ly/20PrE

http://adf.ly/20PrE

http://adf.ly/?id=624707

http://adf.ly/20PrE

http://adf.ly/20PrE

http://adf.ly/20PrE

http://adf.ly/20PrE

http://adf.ly/20PrE

http://adf.ly/20PrE

http://adf.ly/20PrE

http://adf.ly/20PrE

http://adf.ly/20PrE

http://adf.ly/20PrE

http://adf.ly/20PrE

http://adf.ly/20PrE


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.