1. Are you ready for the Galaxy S20? Here is everything we know so far!

how to move to another activity in android application

Discussion in 'Android Development' started by ritusingh, Dec 16, 2009.

  1. ritusingh

    ritusingh Lurker
    Thread Starter

    Hi Frens...

    Can anyone please tell me that how to move from one activity to another using the class intent.
    i have followed the code:-

    Intent intent=new Intent();
    in.setClass(this.MainActivity,subactivity.class);
    startActivity(intent);

    this code is not working .
    what changes should i made so that i can able to execute my program?
    pls help me out.

    Thanx-
    Ritu Singh
     


  2. victoria122

    victoria122 Lurker

    Code (Text):
    1. Intent i = new Intent(this,subactivity.class);
    If you do not want a response and are simply moving to the next screen without needing to go back:
    Code (Text):
    1.  
    2. startActivity(i);
    3. finish();
    4.  
    If you need a result from the subactivity and need to go back to the parent activity:
    Code (Text):
    1.  
    2. startActivityForResult(i, number);
    3.  
    And you will need to add method:
    Code (Text):
    1.  
    2. protected void onActivityResult(int requestCode, int resultCode, Intent data)
    3.  
     
Loading...

Share This Page

Loading...