डिस्रेगर्ड करें। मैं स्थापित गलत ऐप खोल रहा था। यह अद्भुत काम करता है। :)बैक बटन के साथ एंड्रॉइड वेबव्यू, यदि अन्य
मेरे पास बैक बटन मेरे वेबव्यू में सही तरीके से काम कर रहा है, लेकिन मैं कुछ सोच रहा था। वेबव्यू को तब तक वापस कैसे करें जब तक यह और नहीं हो सकता है, और प्रोग्राम से बाहर निकलने के बजाय, क्या यह एक संवाद बॉक्स खोलता है कि क्या यह सुनिश्चित है कि उपयोगकर्ता बाहर निकलना नहीं है। यहां कोड पर मेरा लेना है।
समय लेने के लिए धन्यवाद।
जावा फाइल
package com.vtd.whatthe;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.widget.Toast;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class WhatThe extends Activity {
private WebView webview;
/** Called when the activity is first created. */
public void onBackPressed(){
if (webview.isFocused() && webview.canGoBack()) {
webview.goBack();
}
else {
openMyDialog(null);
}
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
webview = (WebView) findViewById(R.id.webview);
webview.setWebViewClient(new HelloWebViewClient());
webview.getSettings().setJavaScriptEnabled(true);
webview.setInitialScale(50);
webview.getSettings().setUseWideViewPort(true);
webview.loadUrl("http://test2.com/");
}
private class HelloWebViewClient extends WebViewClient {
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
}
public void openMyDialog(View view) {
showDialog(10);
}
@Override
protected Dialog onCreateDialog(int id) {
switch (id) {
case 10:
// Create our AlertDialog
Builder builder = new AlertDialog.Builder(this);
builder.setMessage("Are you sure you want to exit? You have unlimited guesses!")
.setCancelable(true)
.setPositiveButton("Yes",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,
int which) {
// Ends the activity
WhatThe.this.finish();
}
})
.setNegativeButton("Keep Guessing!",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,
int which) {
Toast.makeText(getApplicationContext(),
"Good Luck!",
Toast.LENGTH_SHORT).show();
}
});
return builder.create();
}
return super.onCreateDialog(id);
}
}
खुशी है कि आप यह काम कर रहा है की कोशिश करो। आप [इस ब्लॉग पोस्ट] को पढ़ना चाहेंगे (http://android-developers.blogspot.com/2009/12/back-and-other-hard-keys-three-stories.html) वैसे भी। –