我有3個活動 - A,B和C.我有一個活動A的列表,如果點擊它,它會進入活動B.在活動B上,我有與下面的代碼打開活性C(網頁瀏覽器)按鈕:WebView的問題...回到之前的活動
buyButton = (Button) findViewById(R.id.buyButton);
buyButton.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
System.out.println("!!! buy !!!");
/*Uri uri = Uri.parse("http://www.google.com");
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);*/
Intent startActivity = new Intent(getApplicationContext(), WebViewer.class);
startActivity.putExtra("link","http://www.google.com");
startActivityForResult(startActivity, 15);
}
});
現在,當我按下網頁瀏覽器活動C中的後退按鈕,活動B還關閉。我不確定爲什麼會這樣。任何提示?謝謝。
Web查看代碼:
public class WebViewer extends Activity {
ImageButton backButton;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.streams);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.window_title3);
String url = "";
Bundle extras = getIntent().getExtras();
if(extras !=null) {
url = extras.getString("link");
}
if (!url.startsWith("http://") && !url.startsWith("https://"))
url = "http://" + url;
final TextView title=(TextView) findViewById(R.id.title_text_view_success3);
//title.setText("Saved Streams");
backButton = (ImageButton) findViewById(R.id.back_button3);
backButton.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
System.out.println("!!! BACK !!!");
//finishActivity(0);
onBackPressed();
}
});
setContentView(R.layout.viewer);
final WebView webView = (WebView) findViewById(R.id.webview);
webView.getSettings().setJavaScriptEnabled(true);
webView.setWebChromeClient(new WebChromeClient() {
public void onProgressChanged(WebView view, int progress)
{
title.setText("Loading...");
WebViewer.this.setProgress(progress * 100);
if(progress == 100)
title.setText(webView.getTitle());
}
});
webView.setWebViewClient(new WebViewClient() {
@Override
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl)
{
// Handle the error
}
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url)
{
view.loadUrl(url);
return true;
}
});
webView.loadUrl(url);
}
}
我認爲問題在於你正在使用startActivityForResult()這導致Activity B關閉。 –
@surisahani:那麼,你有什麼建議? – ahsan
只需通過startActivity試試代碼即可。 –