我正试图将事件从一个贾瓦人阶层传到活动。
假设情况是,土著人口将掌握一些土著数据,因此,土著人口将称呼back功能。 这一类处理数据,经过处理,即需要更新数据分析。 我想在活动手里的某个地方更新情报调查。 (Dont 我想在任何地方使用OniThread()。)
I was not able to send the events properly with the below approaches.
1st Approach:
1) Define functions for posting messages in to the queue and call these functions.
2) To call the above mentioned functions (point 1) we need context, if i maintain the static variable for maintaining the context and returning it, if the activity is created twice we wont able to get the write context for the first activity.
public class Activity1 {
protected static Context myContext = null;
protected Handler myHandler = null;
@override
public void onCreate() {
myContext = this;
myHandler = new Handler();
}
public static Context getMyContext() {
return myContext;
}
public void postEvent1() {
myHandler.sendMessage();
}
}
2nd Approach:
1) Making the handler as a static variable and returning this with the help of static function. - Not a good design to expose the internal variables.
2) Cons will be like above, when a second activity is created.
public class Activity1 {
protected static Handler myHandler = null;
@override
public void onCreate() {
myHandler = new Handler();
}
public static Context getMyHandler() {
return myHandler;
}
}
能否利用静态变量和静态功能来了解活动的背景?
如果任何人知道:
Thanks & Regards,
SSuman185