public class Check extends Activity implements OnClickListener {
//private check2 check2;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button usemirror = (Button)findViewById(R.id.widget28);
usemirror.setOnClickListener(this);
}
public void onClick(View view){
Intent mi = new Intent(this , check2.class);
startActivity(mi);
}
}
package com.exaple;
import android.app.Ac开发者_开发知识库tivity;
import android.os.Bundle;
import android.widget.Toast;
public class check2 extends Activity {
public void onCreate(Bundle savedInstanceState) {
// super.onCreate(savedInstanceState);
// setContentView(R.layout.main);
Toast.makeText(
this,
"Welcome to second page", Toast.LENGTH_LONG).show();
finish();
}
}
ANDROID manifest.xml
<activity android:name=".check2" >
I am doing this but doesn't show me the message written in my other activities
@Uttam Didn't you got super not called exception
?
I suppose you must call super.onCreate()
in your check2.Not calling this in your check2 is causing Force Close
public class check2 extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); //first call super.onCreate()
Toast.makeText(
this,
"Welcome to second page", Toast.LENGTH_LONG).show();
finish();
}
I suppose you still need to add:
@Override
public void onPause(){
super.onPause();
}
to both first and second activities.
Please change your first activity code as below
public class Check extends Activity implements OnClickListener {
//private check2 check2;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button usemirror = (Button)findViewById(R.id.widget28);
usemirror.setOnClickListener(this);
}
public void onClick(View view){
Intent mi = new Intent(Check.this , check2.class);
startActivity(mi);
}
}
& second activity code as below
public class check2 extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); //first call super.onCreate()
Toast.makeText(
this,
"Welcome to second page", Toast.LENGTH_LONG).show();
finish();
}
精彩评论