基础代码如下:
注意要在AndiondManifest.xml文件中注册Activity
MainActivity页面
package test.com.myapplication2
;
import android.content.Intent ;
import android.os.Bundle ;
import android.support.v7.app.AppCompatActivity ;
import android.view.View ;
import android.widget.Button ;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState) ;
setContentView(R.layout. activity_main) ;
Button but_exe = (Button) findViewById(R.id. button_exe) ;
but_exe.setOnClickListener( new View.OnClickListener() {
public void onClick(View view) {
Intent intent = new Intent() ;
intent.setClass(MainActivity. this,SecActivity. class) ;
MainActivity. this.startActivity(intent) ;
}
}) ;
}
import android.content.Intent ;
import android.os.Bundle ;
import android.support.v7.app.AppCompatActivity ;
import android.view.View ;
import android.widget.Button ;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState) ;
setContentView(R.layout. activity_main) ;
Button but_exe = (Button) findViewById(R.id. button_exe) ;
but_exe.setOnClickListener( new View.OnClickListener() {
public void onClick(View view) {
Intent intent = new Intent() ;
intent.setClass(MainActivity. this,SecActivity. class) ;
MainActivity. this.startActivity(intent) ;
}
}) ;
}
}
SecActivity页面
package test.com.myapplication2
;
import android.app.Activity ;
import android.os.Bundle ;
import android.widget.Button ;
/**
* Created by rog-pc on 2017/5/6.
*/
public class SecActivity extends Activity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState) ;
setContentView(R.layout. second) ;
Button but_exe = (Button) findViewById(R.id. button_exe) ;
}
import android.app.Activity ;
import android.os.Bundle ;
import android.widget.Button ;
/**
* Created by rog-pc on 2017/5/6.
*/
public class SecActivity extends Activity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState) ;
setContentView(R.layout. second) ;
Button but_exe = (Button) findViewById(R.id. button_exe) ;
}
}
AndiondManifest.xml文件
<?
xml version=
"1.0"
encoding=
"utf-8"
?>
<manifest xmlns: android = "http://schemas.android.com/apk/res/android"
package= "test.com.myapplication2" >
<application
android :allowBackup= "true"
android :icon= "@mipmap/ic_launcher"
android :label= "@string/app_name"
android :supportsRtl= "true"
android :theme= "@style/AppTheme" >
<activity android :name= ".MainActivity" >
<intent-filter>
<action android :name= "android.intent.action.MAIN" />
<category android :name= "android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android :name= ".SecActivity" >
</activity>
</application>
</manifest>
<manifest xmlns: android = "http://schemas.android.com/apk/res/android"
package= "test.com.myapplication2" >
<application
android :allowBackup= "true"
android :icon= "@mipmap/ic_launcher"
android :label= "@string/app_name"
android :supportsRtl= "true"
android :theme= "@style/AppTheme" >
<activity android :name= ".MainActivity" >
<intent-filter>
<action android :name= "android.intent.action.MAIN" />
<category android :name= "android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android :name= ".SecActivity" >
</activity>
</application>
</manifest>