我是Android的初学者。我正在尝试通过 onclick 事件中的意图开始一个新活动。这在模拟器中运行良好。但是当我在真实设备中尝试它时它不起作用并且应用程序再次进入主屏幕。logcat 中没有显示错误。
这就是我调用该startActivity
方法的地方。
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();
}
}
});
新活动如下所示。
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);
}
}
正如我之前解释的,这在模拟器中运行良好。但它在真实设备中不起作用。我找不到哪里出错了。有人可以帮我吗?