Jump to content
Android Forum - A Community For Android Users and Enthusiasts

Get activity instance


Recommended Posts


I have 2 classes that extend "Activity", MyActivityA.java and MyActivityB.java.

How do I start MyActivityB from MyActivityA and access its variables?

Comming from C++ I would expect something like:



MyActivityB actB=new MyActivityB();


actB.startActivity(new Intent(this, MyActivityB.class));


But this doesn't work. It throws an exception. By searching online I allways see starting an activity like this:



startActivity(new Intent(this, MyActivityB.class));

//But now how do I get an instance to MyActivityB class that was started?


I would really prefer to access the MyActivityB class public variables.

I know of passing parameters in the Intent using putExtra(), but I am looking for an alternative because of the complexity of the project that I am not going to discuss about here.



Link to comment
Share on other sites

  • 11 months later...
  • 5 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...