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 3357378
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T02:37:32+00:00 2026-05-18T02:37:32+00:00

I want to send back my activity to starting one. Let me explain you.

  • 0

I want to send back my activity to starting one. Let me explain you.
I am using Main activity having 4 tabs, and each tabs has his own activity. Each activity in has more activities in it.
Problem starts when I click on 1st activity in my 1st tab. The next activity is independent. I create an intent of my next activity. In such case to prevent draw my tab-bar layout in that new activity. I use my existing activity layout, remove all the view in it. Then i put new activity in it.

e.g..
contentViewLayout.removeAllViews();
View view = activityManager.startActivity(id, intent).getDecorView();
contentViewLayout.addView(view, contentViewLayoutParams);

Its done. But problem arise when device BACK button pressed. Because new activity is starting in existing activity. So when back button pressed , then it quite to main activity and application close. I want to do that in such a case “new activity” should be terminate and existing activity must start again. And then if again BACK button pressed then it should terminate main activity.
I override the onKeyDown() down method as follow but it. dose not working properly?

In my new activity.

public boolean onKeyDown(int keyCode, KeyEvent event) {

    if(keyCode == KeyEvent.KEYCODE_BACK){

            childActivity = null;
            contentViewLayout.removeAllViews();
                            mainActivity = new Intent(this,MainActivity.class);
                            View view = activityManager.startActivity(id, intent).getDecorView();
                             contentViewLayout.addView(view, contentViewLayoutParams);
            return false;
    }else{
        return super.onKeyDown(keyCode, event);
    }
}

But it always quite the application instead of closing child activity

  • 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-18T02:37:33+00:00Added an answer on May 18, 2026 at 2:37 am

    I got it!
    Actually the focused activity was the main activity… not the new activity. So all we have to do to set focused to our new activity. So in onCreate() method of new activity I put focused to one any component in new activit e.g..

    button.setFocusable(true);
    button.requestFocus();

    So in such a case new activity onKeyDownButtonWorks

    Blockquote

        @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if(event.getKeyCode() == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0 ){
                                //My code goes here.
                return true;
        }
        return super.onKeyDown(keyCode, event);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Like i can send data from one activity to another using this: intent.putExtra(Name, Value);
I want to received raw TCP packet and then send it back with same
In my application i want send a email to one account.in one button click
I want to send back formatted messages from my domain, For example things like:
This has been killing me for two days now. I have a main Activity
This has been killing me for two days now. I have a main Activity
I want to sent intent from one first activity to another. The first activity
I want send e-mail with some images in content. I think I must attached
I want send a email by Email Class in codeigniter with gmail, but i
Hello Sir i want send list of data to php server i use following

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.