I am a beginner in Android. I am trying to start a new activity via an intent inside an onclick event. This works fine in emulator. But when I try it in a real device it doesn't work and the application goes to the main screen again. No errors are shown in the logcat.
This is where I call the startActivity
method.
relativeAbout.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
try {
Class OurClass = Class
.forName("com.wad.tourismguide.AboutCity");
Intent newIntent = new Intent(getApplicationContext(),
OurClass);
newIntent.putExtra("name", name);
newIntent.putExtra("detail", detail);
newIntent.putExtra("image", main);
startActivity(newIntent);
System.out.println("intent starting");
} catch (ClassNotFoundException e) {
// TODO: handle exception
e.printStackTrace();
}
}
});
The new activity is shown below.
public class AboutCity extends Activity {
TextView cityName;
ImageView image;
TextView detailText;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.aboutcity);
cityName = (TextView)findViewById(R.id.tvDetailCityName);
image = (ImageView)findViewById(R.id.ivDetailImage);
detailText = (TextView)findViewById(R.id.tvDetailText);
String name = getIntent().getStringExtra("name");
System.out.println("city name"+ name);
String detail = getIntent().getStringExtra("detail");
System.out.println("city detail"+ detail);
Bitmap b= (Bitmap)getIntent().getParcelableExtra("image");
System.out.println(detail);
cityName.setText(name);
detailText.setText(detail);
image.setImageBitmap(b);
}
}
As I explained earlier, this works fine in the emulator. But it doesn't work in the real device. I can't find where I am going wrong. Can someone please help me with this?