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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T20:31:28+00:00 2026-06-01T20:31:28+00:00

I’m currently moving slowly but steady forward in the making of a Android application

  • 0

I’m currently moving slowly but steady forward in the making of a Android application and Im currently learning how to create a new window and switch to it. This is going all well but I have one small problem. When I pressing the “go back” button closes the application even if I have choosed to go back when just that button is pressed.

@Override
public void onBackPressed() {
    finish();
    return;
}

Have I missed something or what?

Thanks in advance.

EDIT

@Override
public boolean onCreateOptionsMenu(Menu menu)
{
    MenuInflater menuInflater = getMenuInflater();
    menuInflater.inflate(R.menu.main, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item)
{       
    // Handle item selection
    switch (item.getItemId())
    {
    case R.id.menuItem1:
        setContentView(R.layout.about);
        return true;
    case R.id.menuItem2:
        System.exit(0);
        return true;
    default:
        return super.onOptionsItemSelected(item);
    }
}

EDIT 2: About.java

package weather.right;

import weather.right.now.R;
import android.os.Bundle;

public interface About {
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.about);
    }

}
  • 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-06-01T20:31:30+00:00Added an answer on June 1, 2026 at 8:31 pm

    You need to use Intents to “switch windows”. A “window” is called an Activity in Android and you set the visual content of an Activity using the setContentView() method in the onCreate() call of the Activity.

    To launch another Activity from your current Activity, simply create an Intent with a few parameters and call startActivity() with that Intent. Here’s an example:

    Intent i = new Intent(this, TheNextActivity.class);
    startActivity(i);
    

    Don’t forget to include your second Activity in the Android manifest file. All Activities in your application must be included in that file.

    Other things to note is that you don’t really use System.exit() in Android. Just call finish(). It’s advised to let Android manage applications and its resources rather than doing it yourself, but if you want to make sure that your application really is shut down, feel free to use System.exit() anyway. There’s also no need for overriding onBackPressed() if you’re only calling finish(). That’s standard behaviour in Android when you hit the back button.

    Also, you don’t call setContentView() more than once per Activity. You start a new Activity when you need to change the visuals (or use one of the specialized Widgets to switch between layouts.

    This also explains why you’re experiencing your “problem”. You may have changed the layout of the Activity using setContentView(), but there’s still only one Activity running – when you call finish(), that Activity gets closed. If you had started a second Activity with a different layout, like you’re supposed to do, Android would have closed that second Activity and would have returned you to the first.

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

Sidebar

Related Questions

I want use html5's new tag to play a wav file (currently only supported
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
This could be a duplicate question, but I have no idea what search terms
I am currently running into a problem where an element is coming back from
Seemingly simple, but I cannot find anything relevant on the web. What is the

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.