//第一个java代码
//HelloWorldActivity.java
package com.example.android.helloworld;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;
public class HelloWorldActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
public void openWeb(View view)
{Intent webIntent=new Intent(Intent.ACTION_VIEW,Uri.parse("http://nokiaguy.blogjava.net"));
startActivity(webIntent);
}
public void openNew(View view){
Intent intent=new Intent(HelloWorldActivity.this,OtherActity.class);
intent.putExtra("name", "wjh");
intent.putExtra("age", 21);
startActivity(intent);
}
public void onDestory(){
super.onDestroy();
Toast.makeText(this, "onDestory", Toast.LENGTH_SHORT).show();
}
public void onPause(){
super.onPause();
Toast.makeText(this,"onPause", Toast.LENGTH_SHORT).show();
}
public void onRestar(){
super.onRestart();
Toast.makeText(this, "onRestar", Toast.LENGTH_SHORT).show();
}
public void onResume(){
super.onResume();
Toast.makeText(this, "onResume", Toast.LENGTH_SHORT).show();
}
public void onStar(){
super.onStart();
Toast.makeText(this, "onStar", Toast.LENGTH_SHORT).show();
}
public void onStop(){
super.onStop();
Toast.makeText(this, "onstop", Toast.LENGTH_SHORT).show();
}
public void onMyButtonClick(View view)
{
Toast.makeText(this,"Button clicked",Toast.LENGTH_SHORT).show();
}
}
//第二个java代码
//OtherActivity.java
package com.example.android.helloworld;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TextView;
public class OtherActity extends Activity{
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.other);
Intent intent=getIntent();
String name=intent.getStringExtra("age");
int age=intent.getIntExtra("age",0);
TextView textView=(TextView)findViewById(R.id.textview1);
textView.setText("name:"+name+",age:"+age);
}
}
main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@+string/hello" />
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@+string/Button_1"
android:onClick="onMyButtonClick"/>
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@+string/button_2"
android:onClick="openNew"/>
<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@+string/linlaninternet"
android:onClick="openWeb"/>
<Button
android:id="@+id/button4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@+string/useBundle"
android:onClick="bundle"/>
</LinearLayout>
oher.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="你好。。。" />
<TextView
android:id="@+id/textview1" android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="第二个textview"/>
</LinearLayout>