从一项活动过渡到另一项活动时,我遇到了奇怪的问题。实际上,当我尝试导航到愿意的活动时,应用程序崩溃并重新启动当前活动。这是一些代码:
// Home Activity
Intent intent = new Intent(Home.this, News.class);
intent.putExtra("category", categories[currentCategory]);
intent.putExtra("newstext", (rssList.get(position)).getData());
startActivity(intent);
这是来自News Activity的源代码:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.requestWindowFeature(FEATURE_NO_TITLE);
this.getWindow().setFlags(FLAG_FULLSCREEN, FLAG_FULLSCREEN);
setContentView(R.layout.news);
savedInstanceState = getIntent().getExtras();
String category = savedInstanceState.getString("category");
String newstext = savedInstanceState.getString("newstext");
activeCategory = (TextView)findViewById(R.id.hActiveCategory);
activeCategory.setText(category);
returnBtn = (Button)findViewById(R.id.Return);
returnBtn.setOnClickListener(returnClick);
String encoding = getResources().getString(R.string.encoding);
String mimeType = getResources().getString(R.string.mimetype);
wv = (WebView) findViewById(R.id.WebView);
wv.loadData(newstext, mimeType, encoding);
}
它仅在我使用AVD emulator测试时才能正常工作。
当我导航到News Activity时,这两行来自CogCat:
07-12 16:41:35.431: I/ActivityManager(292): START u0 {cmp=com.rss.reader/.News (has extras)} from pid 4741
07-12 16:41:35.910: I/ActivityManager(292): Displayed com.rss.reader/.News: +452ms