已经开发了许多桌面GUI程序(从Xt的Qt的,Java的AWT / SWT / Swing的,等等),我真的觉得很难习惯到Android。
Having developed many desktop GUI apps (from Xt to Qt, Java Awt/Swt/Swing, etc) I really find it difficult to get used to Android.
假设我有它通过意向机制明确要求DetailedView如下图所示的活动的MainView类:
Suppose I have the MainView Activity class which explicitly calls DetailedView via intent mechanism as shown next:
-
由于一个Activity类通过的onCreate()实例化我怎么 定制呢? (无构造函数,只 通过意图传递数据!)
Since an Activity class is instantiated via onCreate() how do I customize it? (No constructor, only pass data through intent!)
有没有办法让在DetailedView实例的引用 MainActivity?
Is there a way to get a reference for the DetailedView instance in MainActivity?
有没有办法让在MainActivity实例的引用 DetailedView?
Is there a way to get a reference for the MainActivity instance in DetailedView?
如何通过引用前端到DetailedView类? Intent.putExtras()只允许 某些数据类型传递给 意图接收器类。
How can I pass the reference to FrontEnd to the DetailedView class? Intent.putExtras() allows only for certain data types to pass to the intent receiver class.
MainActivity { ... FrontEnd fe; ... public void onCreate(Bundle savedInstanceState) { ... Intent myIntent = new Intent(this, DetailedView.class); ... } protected void onListItemClick(ListView l, View v, int position, long id) { ... startActivityForResult(myIntent,..); ... }}
}
推荐答案
我经常欺骗和使用静态'的getInstance呼吁活动和观点之间的通信。这个工作,只要他们都在同一个进程内,而我还没有有一个数据访问失败...但我敢肯定,这只是一个时间的问题。如果你正在寻找一个哈克快速修复,这可能是它,否则,您必须通过意图传递数据。
I frequently cheat and use static 'getInstance' calls to communicate between Activities and views. This works as long as they're both in the same proc, and I've yet to have a data access failure...but I'm sure it's only a matter of time...IF you're looking for a hacky quick fix this could be it, otherwise you have to pass data through intents.
更多推荐
通过意图传递构造的数据,而不是
发布评论