在一种方法中,我开始了一项新 Activity

public void start(){
    Intent i = new Intent(mContext, Screen.class);
    mContext.startActivity(i);
    //Here i want to get the new activity

    Activity a = ...
    //Do something with new activity

}

调用starActivity()之后,我需要获取该新的Activity并对其进行处理。

是否可以??

编辑:

好吧,我的Screen类上有以下方法:
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    loadedScreen = false;
}


public void loadScreen(String folderResources, String nameXml, String nameScren){
         //Do something
    }
loadScreen读取XML文件并通过代码在所有用户界面中创建,而不是在onCreate中进行

在另一个类中,我调用foo():
public void goToScreen(String nameScreen){
    Class screen = Screen.class;
    Intent i = new Intent(mContext, screen);
    mContext.startActivity(i);

    //Here in screen.getMethod... i need use a instance of Screen, which i think it have to be created in `startActivity()`

        Method loadUrl = screen.getMethod("loadScreen", String.class, String.class, String.class);

      loadUrl.invoke(screen, "folder-s","screen1","screen1.xml");


}

我需要在loadScreen之后调用startActivity,因为此方法会加载所有 View 。我使用反射来做到这一点。所以我需要获得新的 Activity

最佳答案



一旦调用startActivity(),其他 Activity 将不存在-一段时间将不存在。



loadScreen() Activity 的onCreate()调用Screen

如果希望将folderResourcesnameXmlnameScren的值传递给Screen,请通过在与putExtra()一起使用的Intent上调用startActivity()来实现。然后,Screen可以在getIntent().getStringExtra()中调用onCreate()来检索这些值,以便将它们传递给loadScreen()

10-07 16:23