![](/img/trans.png)
[英]Accessing method from activity that will start another activity from a class
[英]Accessing method in main activity from another class
如何從另一個類訪問方法myMethod?
public class controller extends Activity
{
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
int myMethod() {int id = 0; return id;} //arbitrary example, may also be static?
}
您將controller
Activity
傳遞給另一個類,就像使用Java中的任何其他對象一樣。 請注意不要在可能導致垃圾回收問題的地方使用“ Activity
(例如,服務,靜態數據成員,自定義Application
對象)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.