If this is what you currently do:
In your Activity, you call a method that winds up parsing some XML. Then you
have implement an xml-handler (content-handler), that has no idea of how to
get at the 'current activity'... And you need that activity (or at least the
application-context associated with that activity) to get some data
(strings, integers and such) from the resources (/res directory). Is this
correct?
One way of doing this is to create a class that just holds global vars:
public abstract class GlobalVars {
public Activity currentActivity = null;
}
Just before you start parsing your XML in your Activity' code:
*GlobalVars.currentActivity* = this; // where 'this' is your activity.
...
parseSomeXmlFile(xmlFile);
...
And, an example, in your XML-handler called while your xmlFile is being
parsed:
*GlobalVars.currentActivity*.getString(R.string.some_string_id);
If you need to make it thread-safe, I suggest you using ThreadLocal instead
to store the 'currentActivity' or some other 'Context' variable.
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en