从一个页面activity转向另一页面

     导入

import android.content.Intent;


从 StarloveActivity (当前页面) 转到 star(另一个页面)


   Intent intent = new Intent();  

        intent.setClass(StarloveActivity.this, star.class);
        startActivity(intent);   
        StarloveActivity.this.finish(); 


Activity中使用Intent实现页面跳转与参数的传递


新建一个FirstAvtivity.java

复制代码
    
    
    
    
package com.zhuguangwei; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; public class FirstActivity extends Activity { private Button myButton; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super .onCreate(savedInstanceState); setContentView(R.layout.main); myButton = (Button) findViewById(R.id.myButton); myButton.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub Intent intent = new Intent(); // Intent传递参数 intent.putExtra( " testIntent " , " 123 " ); intent.setClass(FirstActivity. this , SecondActivity. class ); FirstActivity. this .startActivity(intent); } }); } }
复制代码
新建第二个SecondActivity.java

复制代码
    
    
    
    
package com.zhuguangwei; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.widget.TextView; public class SecondActivity extends Activity{ private TextView myTextView; @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super .onCreate(savedInstanceState); setContentView(R.layout.other); // 使用Intent对象得到FirstActivity传递来的参数 Intent intent = getIntent(); String value = intent.getStringExtra( " testIntent " ); myTextView = (TextView) findViewById(R.id.myTextView); myTextView.setText(value); } }
复制代码

两个Activity都要在AndroidMenifest.xml中注册


你可能感兴趣的:(String,Class,import,button)