I know that we can start new activity with the steps as follows :
- Design new XML file that contains layout details ( LinearLayout,
RelativeLayout, etc ) and add user defined widgets ( Button, TextView, … ) -
Add activiy name and label details to AndroidManifest.xml like below
<activity android:name=".NewActivity" android:label="@string/new_activity_header" /> - Define new Intent and call startActivity to start new activity.
But, i want to start new activity with start argument that will be changed in different calls.
For example :
-
Main activity XML layout file:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/button" /> </LinearLayout>
I want to do this :
If we press Button, new activity will be started and show the random number that generated in main activity.
Button btn = (Button) findViewById(R.id.button);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int rand = new Random().nextInt(10000);
//Some code will be placed here !
}
});
But how can i initialize new activity class field members?
Thanks in advance 🙂
try:
and in your activity: