Starting Another Activity
step 1 : create a xml for MainActivity ( activity_main.xml )
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/click" />
<Button
android:id="@+id/jump"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/forword"
android:onClick="jump"
/>
</LinearLayout>
step 2 : create a xml for AnotherActivity ( activity_another.xml )
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/infomation" />
</LinearLayout>
step 3 : create a class (AnotherActivity.java)
package com.example.startanotheractivity;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
public class AnotherActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_another);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.another, menu);
return true;
}
}
step 4 : modify MainActivity.java
package com.example.startanotheractivity;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
public class MainActivity extends Activity {
private Button jump ;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
jump = (Button) findViewById(R.id.jump);
}
public void jump(View view) {
Intent jumpIntent = new Intent(this,AnotherActivity.class);
startActivity(jumpIntent);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
notice : the Modifier of method jump that define in activity_another.xml must be public
other resource : ( strings.xml )
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">StartAnotherActivity</string>
<string name="action_settings">Settings</string>
<string name="click">Click on the button below, jump to the next Activity</string>
<string name="forword">Jump</string>
<string name="infomation">I am second Activity</string>
</resources>
ScreenShot
--------------------->