Home

Monday 20 April 2015

Starting new Activity(Intents)

Starting new Activity :

Intents are used to transfer the flow of control from current activity to another. They used as messages which are passed and can also be used to pass data.

To create an Intent :

1
2
Intent intent = new Intent(CurrentActivity.this, NewActivity.class);
startActivity(intent);

To pass data :

We will pass a string "Extra_Data" :


1
2
3
Intent intent = new Intent(CurrentActivity.this, NewActivity.class);
intent.putExtra("Extra_DataId", "Extra_Data");
startActivity(intent);

To receive data in another activity : 

1
String data= getIntent().getStringExtra("Extra_DataId");

No comments:

Post a Comment