WhiskThimble
WhiskThimble

Reputation: 597

getResource from a Thread

I have problems getting a String from the strings.xml file (in the directory res/values). In my Remote Service, I start a Thread in which I want to access some Strings from strings.xml.

For this, I use :

AcquisitionThread(Context context) {
    myServiceContext = context;
}

@Override
    public void run() {
        super.run();
        myServiceContext.getResources().getString(R.string.base_text_conso);
}

I construct the Thread from my Remote Service this way :

myAcquisitionThread = new AcquisitionThread(getBaseContext());

This is what I read should work, on many subjects.

I don't understand why something as simple as this can fail. Maybe it is because of the Thread created from the Service or something else. Any idea?

Last precision : my Remote Service extends service and my Thread extends thread

Upvotes: 0

Views: 420

Answers (2)

WhiskThimble
WhiskThimble

Reputation: 597

Looking this post : Android, string resource not found I realised that an import android.R; was in my imports. This is an issue you can have when you import too much things without really looking at them.

In order to fix the problem, just delete the import android.R; line (you don't need anything else to replace it)

Upvotes: 1

Nelson Almendra
Nelson Almendra

Reputation: 881

Why don't you get the getString(R.string.base_text_conso) in your Activity and pass it through the intent that you are using to call startService() using putExtra() method?

Upvotes: 0

Related Questions