如何在设备上停止活动设备点击后退按钮

时间:2014-04-30 15:04:13

标签: android button android-activity

回答和信任的评论! 谢谢sania

  public class Test extends Activity {

HTML5WebView mWebView;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mWebView = new HTML5WebView(this);
    Intent i = getIntent();
    String url = i.getStringExtra("url");  // retrieve the value you passed

    if (savedInstanceState != null) {
        mWebView.restoreState(savedInstanceState);
    } else {    
        mWebView.loadUrl(url);  // use that value
    }

setContentView(mWebView.getLayout());
}

    @Override
    public void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        mWebView.saveState(outState);
    }

    @Override
    public void onStop() {
        super.onStop();
        mWebView.stopLoading();
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
   if (keyCode == KeyEvent.KEYCODE_BACK) {
       onBackPressed();

   }

   return super.onKeyDown(keyCode, event);
   }

    public void onBackPressed() {
   Intent myIntent = new Intent(Test.this, fragment_main.class);
   myIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);// clear back stack
   startActivity(myIntent);
   finish();
   return;


    }  
}

单击后退按钮时如何停止上次活动?我是一个使用listview的vimeo应用程序,如何停止和关闭(vimeo videoplayer.class)该活动。当我点击后退按钮时它的第一个活动或显示消息应用程序已停止:/

1 个答案:

答案 0 :(得分:0)

在backkey方法中添加ondestroy()或video.stop()方法