我的应用程序只运行一次,在第二次运行(和其他......)时,我得到了“不幸的是,myapp 已停止”。我已经尝试了很多,但对我没有任何影响。这是代码:
MainActivity:包com.example.myfirstapp;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
public class MainActivity extends Activity {
public void onCreate(Bundle savedInstanceState) {
final Context context = this;
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Intent intent = new Intent(context, WebViewActivity.class);
startActivity(intent);
}
@Override
protected void onStart() {
super.onStart();
// The activity is about to become visible.
}
@Override
protected void onResume() {
super.onResume();
// The activity has become visible (it is now "resumed").
}
@Override
protected void onPause() {
super.onPause();
// Another activity is taking focus (this activity is about to be "paused").
}
@Override
protected void onStop() {
super.onStop();
// The activity is no longer visible (it is now "stopped")
}
@Override
protected void onDestroy() {
super.onDestroy();
// The activity is about to be destroyed.
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected (MenuItem item) {
switch (item.getItemId()) {
case R.id.exit:
finish();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
}
网络视图活动:
package com.example.myfirstapp;
import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class WebViewActivity extends Activity {
private WebView webView;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.webview);
webView = (WebView) findViewById(R.id.webView1);
webView.setWebViewClient(new WebViewClient());
webView.getSettings().setJavaScriptEnabled(true);
webView.loadUrl("http://mysite.com");
}
@Override
protected void onStart() {
super.onStart();
// The activity is about to become visible.
}
@Override
protected void onResume() {
super.onResume();
// The activity has become visible (it is now "resumed").
}
@Override
protected void onPause() {
super.onPause();
// Another activity is taking focus (this activity is about to be "paused").
}
@Override
protected void onStop() {
super.onStop();
// The activity is no longer visible (it is now "stopped")
}
@Override
protected void onDestroy() {
super.onDestroy();
// The activity is about to be destroyed.
}
}
日志猫:
09-05 05:53:27.080: I/Choreographer(815): Skipped 76 frames! The application may be doing too much work on its main thread.
09-05 05:53:27.391: D/dalvikvm(815): GC_FOR_ALLOC freed 88K, 6% free 2654K/2808K, paused 136ms, total 139ms
09-05 05:53:27.760: I/Choreographer(815): Skipped 88 frames! The application may be doing too much work on its main thread.
09-05 05:53:27.771: D/gralloc_goldfish(815): Emulator without GPU emulation detected.
09-05 05:53:27.931: I/Choreographer(815): Skipped 38 frames! The application may be doing too much work on its main thread.
09-05 05:53:28.630: E/chromium_net(815): external/chromium/net/disk_cache/backend_impl.cc:1107: [0905/055328:ERROR:backend_impl.cc(1107)] Critical error found -8
09-05 05:53:28.641: W/chromium_net(815): external/chromium/net/disk_cache/storage_block-inl.h:119: [0905/055328:WARNING:storage_block-inl.h(119)] Failed data load.
09-05 05:53:28.651: D/chromium(815): Unknown chromium error: -401
09-05 05:53:28.670: W/chromium_net(815): external/chromium/net/disk_cache/storage_block-inl.h:119: [0905/055328:WARNING:storage_block-inl.h(119)] Failed data load.
09-05 05:53:29.210: E/cutils-trace(815): Error opening trace file: No such file or directory (2)
09-05 05:53:29.271: D/TilesManager(815): Starting TG #0, 0x2a2a6710
09-05 05:53:58.921: W/IInputConnectionWrapper(815): showStatusIcon on inactive InputConnection
09-05 05:54:00.280: I/Choreographer(815): Skipped 44 frames! The application may be doing too much work on its main thread.