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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T20:03:21+00:00 2026-06-16T20:03:21+00:00

I try to to add an Splash Activity to my application this splash activity

  • 0

I try to to add an Splash Activity to my application
this splash activity open when the program start for first time

but when the app work and skip the splash activity to main activity
and user hold on and go to the home screen

after that the user will return to the app ,,

the problem is here
so the application reopen the splash activity again

i don’t want the app to open the splash activity every time the application resume activity
i need to direct open the main activity …

I tried this code but it doesn’t work with me

In Splash Activity …

public class SplashActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        Class<?> activityClass;

        try
        {
            SharedPreferences prefs = getSharedPreferences("X", MODE_PRIVATE);
            activityClass = Class.forName(prefs.getString("lastActivity", MainActivity.class.getName()));
        }
        catch(ClassNotFoundException ex)
        {
            activityClass = MainActivity.class;
        }

        startActivity(new Intent(this, activityClass));
        
        Button btn = (Button)findViewById(R.id.button1);
        btn.setOnClickListener(new View.OnClickListener()
        {           
            @Override
            public void onClick(View v)
            {
                Intent intent = new Intent(MainActivity.this,Main2Activity.class);
                startActivity(intent);
            }
        }
        );
    }


}

and in the Main Activity i use this code

public class Main2Activity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);
        
    }
    
    
    @Override
    protected void onPause() {
        super.onPause();

        SharedPreferences prefs = getSharedPreferences("X", MODE_PRIVATE);
        Editor editor = prefs.edit();
        editor.putString("lastActivity", getClass().getName());
        editor.commit();
    }

}
  • 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-16T20:03:21+00:00Added an answer on June 16, 2026 at 8:03 pm

    Use Application class to save a global flag:

    public class App extends Application {
        private static boolean sFirstRun = false;
    
        public static boolean fetchFirstRun() {
            boolean old = sFirstRun;
            sFirstRun = false;
            return old;
        }
    
        //--called when app process is created--
        @Override
        public void onCreate() {
            super.onCreate();
    
            sFirstRun = true;
        }
    }
    

    And in manifest.xml add : <application android:name=".App"

    now, App.fetchFirstRun() is true only when App process is created from scratch. As long as app is running subsequent calls will return false.

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

Sidebar

Related Questions

I try to add admob, but I have some problem with it. This is
I actually try to add a Splash Screen to my WPF application. It is
Getting this error when try to add an item to my repositories/context: Collection has
i create project with storyboard base uitabbarcontroller, i try to add splash view that
I try add and compile ffmpeg library in my own android application. When I
I set up splash activity which start another activity after few second. Anyway I
I have this error when I try add ace in class: Warning: PDO::quote() expects
This is the VBA code im using to try add a new sheet to
I try add example from http://ellislab.com/codeigniter/user_guide/tutorial/news_section.html to my site, this is code: news_model <?php
This is my code. When I click on my app logo, after the splash

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.