-
January 26th, 2012, 08:10 AM
#1
Global variables and different threads
Hello! Don't abuse strongly, I yet very well know Java.
Program for Android.
The task: I need in the program the global object containing a string array with the information on a state of the program (logger).
I create class with a static array:
public class FoxLog {
private static ArrayList<String> logList = new ArrayList<String>();
public static int count() {
synchronized(logList) {
return logList.size();
}
}
public static String get(int index) {
synchronized(logList) {
return logList.get(index);
}
}
//Send a DEBUG log message.
static public int d(String tag, String msg) {
add('D', tag, msg);
return Log.d(tag, msg);
}
// Send a ERROR log message
static public int e(String tag, String msg) {
add('E', tag, msg);
return Log.e(tag, msg);
}
}
Method add for brevity eliminated.
Problem in that the program (for the Android) is executed in two different VM. The main flow – GUI and Service, and so similar variable logList different for the main flow and for service.
How to solve the given problem?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|