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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T06:38:24+00:00 2026-06-14T06:38:24+00:00

I have one mainactivity in which the location is determined. In this mainactivity I

  • 0

I have one mainactivity in which the location is determined. In this mainactivity I first add a splashscreen fragment. At the moment I find the first location/GPS is working correctly and found a location, I want to replace this splashscreen with my main menu.
Relevant code in the mainactivity:

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.frame);

    //Check that the activity is using the layout version
    // the framelayout

    if(findViewById(R.id.fragment_container)!=null){
        //To avoid overlapping fragments check if we are restored from a state, then we don't have to do anything
        if(savedInstanceState != null){
            return;
        }

        Splash splashscr = new Splash();
        Main main = new Main();

        getSupportFragmentManager().beginTransaction()
        .add(R.id.fragment_container, splashscr).commit();

    // I **think something should be added here 
//to check if a location has been found yet.**

        FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
        transaction.replace(R.id.fragment_container, main);
        transaction.commit();
        }


}  

I tried adding a while(foundlocation!=true) in that location. The foundlocation would then be set to true in either onLocationChanged() or in the end of getLocation(). However, it didn’t solve my problem. Can someone help me out? If I didn’t make my problem clear enough please say so.

EDIT: After considering the comment of Gabe I tried this (locationfound is a public boolean initiated as false in the activity class). But if I now use the DDMS to send a location the splashscreen won’t go away. If I’m correct, the first time the location is changed, the boolean is still false and thus it should switch fragment.
I tried it without the if statement and then it was working. What do I forget about here?

public void onLocationChanged(final Location location) { 

       if(locationfound=false)
       {
//Some irrelevant code about saving the new location

        Main main = new Main();

        FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
        transaction.replace(R.id.fragment_container, main);
        transaction.commit();

        locationfound=true;
           }

//changing value of sometextboxes in the Main fragment

   }
  • 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-14T06:38:25+00:00Added an answer on June 14, 2026 at 6:38 am

    Don’t try to wait in onCreate- that holds up the UI thread leading to unresponsive UIs. Instead, you should switch the fragments in the onLocationChanged function the first time its called (by using a boolean flag variable to tell if its the first time).

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

Sidebar

Related Questions

I have 2 activities, the first one is the startup one which in it's
I am working on activity which request one php file on server & this
If I have a string variable inside one class MainActivity.selectedFilePath which has a value
i have main activity in which i have Four menus. and i have one
I have a design of activities like this I have one main activity and
I have one XML request which I need to modify (to XML) and then
I have one drop down list in my page, which contains two options. What
So, in my program i have a TabActivity which contains two tabs, one tab
I have a mainActivity which is Customer.java with listview of 5 diff. activities. I
I have a main activity which calls a child one via Intent I =

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.