Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6686427
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:10:13+00:00 2026-05-26T05:10:13+00:00

I have a program with 4 different tabs. One of these tabs is an

  • 0

I have a program with 4 different tabs.

One of these tabs is an ActivityGroup which has a ListView in it. When I click on one of the list items, it switches to WebActivity:

        lv.setOnItemClickListener(new OnItemClickListener() {
          public void onItemClick(AdapterView<?> parent, View view,
              int position, long id) {
              Intent intent = new Intent(TabActivity2.this, WebActivity.class);
              Bundle b = new Bundle();
              b.putString("URL", URLs[(int)id]);
              b.putString("prevActivity", "TabActivity2");
              intent.putExtras(b);
              replaceContentView("web", intent);
          }
        });
    }

    public void replaceContentView(String id, Intent newIntent) {
        View view = getLocalActivityManager().startActivity(id,newIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)) .getDecorView(); this.setContentView(view);
    }

So now we’re in the WebActivity class. Here’s the code:

public class WebActivity extends ActivityGroup {
    WebView mWebView;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.web);

        Bundle b = getIntent().getExtras();
        String URL = b.getString("URL");

        mWebView = (WebView) findViewById(R.id.webview);
        mWebView.getSettings().setJavaScriptEnabled(true);
        mWebView.getSettings().setPluginsEnabled(true);
        mWebView.loadUrl(URL);

        mWebView.setWebViewClient(new FirstTabWebViewClient());        
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if ((keyCode == KeyEvent.KEYCODE_BACK) && mWebView.canGoBack()) {
            mWebView.goBack();
            return true;
        }
        Bundle b = getIntent().getExtras();
        String retActivity = b.getString("prevActivity");
        if (retActivity == "TabActivity2") {
            Intent intent = new Intent(WebActivity.this, TabActivity2.class);
            replaceContentView("list_webpages", intent);
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }
    public void replaceContentView(String id, Intent newIntent) {
        View view = getLocalActivityManager().startActivity(id,newIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)) .getDecorView(); this.setContentView(view);
    }

Here’s the strange thing: If I click on the back button right after I enter the WebActivity class, it closes the application.

But if I first click on any link inside the WebView and then press back twice, then it returns me to the original activity with the ListView.

From using break points in Eclipse I discovered that the program does not even visit onKeyDown if I press the Back button right after I enter the WebActivity view. However, if I click on any link within the WebView and then press the back button, then it goes through my onKeyDown method.

What is going on here??

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T05:10:14+00:00Added an answer on May 26, 2026 at 5:10 am

    Your WebView doesn’t have the focus, which causes the back button to be triggered on top of that (the application stack). If you click on a link it get’s back focus. The WebView has some strange issues concerning focus, have look at this post: Android WebView focus problem

    There you will also find some suggested workarounds to get the focus, you need to call requestFocus() on the WebView at the right place.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a program with 4 different tabs. One of these tabs is an
I have a program in c which receives messages from different clients and servers.
I have a console program that has different components that run like this: void
I have a program which runs two different operations and i'd like to share
I have a program 'foo' running different threads, fooT1, fooT2, .. fooTn. Now if
I have a program with four different buttons. I want to interchange the position
I've got a table recording views of programs. Each program can have two different
I have three different development machines. Do I need three different iPhone Developer Program
I need to write a program used internally where different users will have different
I have recently been put in charge of debugging two different programs which will

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.