Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get Activity after startActivity(Intent i)

In one method i start a new 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        

}

After calling starActivity() i need to get that new Activity and doing something with it.

Is it possible??

EDIT:

Well i have these methods on my Screen class:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    loadedScreen = false;
}


public void loadScreen(String folderResources, String nameXml, String nameScren){
         //Do something
    }

loadScreen read an XML file and create by code all user interface, instead of doing in onCreate

In another class I call 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");


}

I need call to loadScreen after startActivitybecause this method load all views. I use reflection for doing this. So i need get that new Activity

like image 759
Bae Avatar asked Jul 04 '13 15:07

Bae


1 Answers

After calling starActivity() i need to get that new Activity and doing something with it.

Once you call startActivity(), the other activity does not yet exist -- it will not exist for some time.

I need call to loadScreen after startActivitybecause this method load all views.

Call loadScreen() from onCreate() of the Screen activity.

If you wish to pass the values of folderResources, nameXml, and nameScren to Screen, do so by calling putExtra() on the Intent you use with startActivity(). Then, Screen can call getIntent().getStringExtra() in onCreate() to retrieve those values, in order to pass them to loadScreen().

like image 132
CommonsWare Avatar answered Oct 15 '22 04:10

CommonsWare