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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T17:09:06+00:00 2026-06-13T17:09:06+00:00

I have an app start by Splash activity screen for 5 seconds Then open

  • 0

I have an app start by Splash activity screen for 5 seconds Then open Login activity screen then after you put correct user and password open the Menu activity (listActivity) then each row click open MyCity activity.

UPDATE:

What I’m trying to get is: where ever you are in my app, and you go away from my app for any reason not only when you press the home button but also FOR EXAMPLES:

  1. You press home button to check another app then want to return to my app .

  2. You have notification show new message on whatsup or email, you open your whatsup or open email, then return to my app .

3- You left your mobile for period of time then you want to check my app again .

4- you press power button to close the phone ( lock the screen) , then open the lock and want to return back to my app .

what I mean any time you go away my app for any reason but whithout press back back back button which will exit the whole app
then want to return again to my app must open to
you the login screen to re enter your usename and password again.

I Called finish(); for both Splash activity and Login activity .

I tried:android:clearTaskOnLaunch="true" in the Login activity in the manifest but it doesn’thing.

Any advice will be appreciated,

PLEASE WRITE FULL WORKING CODE.

LOGIN ACTIVITY:

 public class Login extends Activity {

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.login);

    Button b = (Button) findViewById(R.id.loginbutton);

  b.setOnClickListener(new OnClickListener() {

  public void onClick(View v) {

    EditText username = (EditText) findViewById(R.id.login);
    EditText password = (EditText) findViewById(R.id.password);

     if(username.getText().toString().length() > 0 && password.getText().
             toString().length() > 0 ) {
if(username.getText().toString().equals("test") && password.getText().
             toString().equals("test")) {


    Intent intent = new Intent(Login.this, Menu.class);
    startActivity(intent);
       finish(); }
            }   }               
                    });  }  }

Menu Activity :

  public class Menu extends ListActivity {

      String classes[] = { "City1", "City2", "City3", "City4", "City5"};

          @Override
      protected void onCreate(Bundle savedInstanceState) {
         // TODO Auto-generated method stub
         super.onCreate(savedInstanceState);

      setListAdapter(new ArrayAdapter<String>(Menu.this,
        android.R.layout.simple_list_item_1, classes));
                                   }

     @Override
       protected void onListItemClick(ListView l, View v, int position, long id) {
         // TODO Auto-generated method stub
          super.onListItemClick(l, v, position, id);
         String cheese = classes[position];
   try {
    Class ourClass = Class.forName("com.test.demo.MyCity");
    Intent ourIntent = new Intent(Menu.this, ourClass);
    ourIntent.putExtra("cheese", cheese);
         startActivity(ourIntent);
           } catch (ClassNotFoundException e) {
        e.printStackTrace();
                            }
                    }}

MyCity Activity :

   public class MyCity extends Activity {
TextView tv1;
String city;
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.city);  

    initializeTextViews();}

private void initializeTextViews() {

    tv1=(TextView)findViewById(R.id.city_tv);
     city=getIntent().getStringExtra("cheese");

if(city.equalsIgnoreCase("City1")){

        tv1.setText(Html.fromHtml(getString(R.string.city1)));}


    else if(city.equalsIgnoreCase("City2")){

        tv1.setText(Html.fromHtml(getString(R.string.city2)));}


    else if(city.equalsIgnoreCase("City3")){

        tv1.setText(Html.fromHtml(getString(R.string.city3)));}


    else if(city.equalsIgnoreCase("City4")){

        tv1.setText(Html.fromHtml(getString(R.string.city4)));}


    else if(city.equalsIgnoreCase("City5")){

        tv1.setText(Html.fromHtml(getString(R.string.city5)));}


    }}

MY MANIFEST:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.test.demo"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="15" />

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >

        <activity
            android:name=".Splash"
            android:label="@string/app_name">   
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <activity
            android:name=".Login"
            android:label="@string/app_name" 
                 android:clearTaskOnLaunch="true">
            <intent-filter>
                <action android:name="com.test.demo.LOGIN" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>

        <activity
            android:name=".Menu"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="com.test.demo.MENU" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>

              <activity
            android:name=".MyCity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="com.test.demo.MYCITY" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
    </application>
</manifest>

SECOND UPDATE : i reached halfway to what i want but still some steps i can’t achieve it explained as below :

BY applying android:clearTaskOnLaunch="true" to Splash activity ,

and prevent back button behaviour on Menu activity :

  @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK) {
       moveTaskToBack(true);
       return true;
            }
    return super.onKeyDown(keyCode, event);
                    } }

SO now when press home button away my app then return to my app its:

go directly to Login activity.

but main goal now is :

if :

SCREEN LOCKED when you are away from your mobile , or press lightly the power button to lock the phone .

or

OPENED MESSAGE from notification

or

OPENED EMAIL from notification

or

you have CALL and answer it ,

THEN return to my app it does not go to login activity but you will return to the page where you was befor .

ANY ADVICE PLEASE , THANKS.

THIED UPDATE :

i used another code for override home button and control the back button rather than appling :android:clearTaskOnLaunch="true" to Splash activity in manifest , just apply the down code to Menu activity:

     @Override
  public boolean onKeyDown(int keyCode, KeyEvent event) {
      if (keyCode == KeyEvent.KEYCODE_BACK) {
       moveTaskToBack(true);
         return true;}

    else if (keyCode == KeyEvent.KEYCODE_HOME) { 
     Intent i=new Intent(Menu.this,Login.class);
       startActivity(i);
          finish();
        return true;}
    return super.onKeyDown(keyCode, event);}
  • 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-13T17:09:07+00:00Added an answer on June 13, 2026 at 5:09 pm

    Here is the solution I came up with.

    Please Download the project at the end of the blog post and test it.

    Tested on:

    • Samsung S3 running android 4.0.4
    • Emulator running android 2.3.1

    The basic idea: We will create a RequireLoginActivity which will be extended by all our activities except the LoginActivity.

    Three cases should be captured when the onResume function is called:

    1. Jumping from one RequireLoginActivity to another RequireLoginActivity using a flavor of startActivity.
    2. Jumping from one RequireLoginActivity back to a previous RequireLoginActivity by finishing the current activity.
    3. Coming back to a RequireLoginActivity after hiding it (we should here show the login!)

    The basic idea of my solution is to have 2 counters: number of Started activities (startCounter) and number of Paused activities (pauseCounter). Each time an activity starts we will increment startCounter. Similarly, when an activity pauses, pauseCounter should be incremented. In our onResume function, we will decide whether to go to the Sign in by comparing the 2 counters. We will gotoLogin() if the 2 counters are equal!

    Let me explain:
    At any time, case 1 can be captured simply because upon starting new activities, our startCounter will always be greater that pauseCounter by 1. This is true because we will always have one extra activity started but not paused.

    Also, case 3 is easily captured, because once you leave our app, say, using the HOME button, we will increment the pauseCounter and the 2 counters will become equal. Once the app is resumed, the onResume will decide to gotoLogin().

    Case 2 is a bit tricky, but simple as well. The trick is by overriding the finish() function and decrementing the startCounter once and the pauseCounter twice in it. Remember that when finishing the activity, onPause is called and our counters are equal. Now by decrementing startCounter once and pauseCounter twice, we ultimately returned to the counters’ values of the previous activity, and startCounter will remain greater the pauseCounter by 1 when the previous activity resumes.

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

Sidebar

Related Questions

In my app have a sign in activity. If login is successful, I start
My app takes a few seconds to load and I have a splash screen.
I hava a WP 7.5 app. I have a splash screen and then comes
I have a loading screen which closes after 5 secounds and then the app
I'm hearing that is better to have one connection open upon app start up
I have a question that I have a splash screen in my android app
The first activity in my app is a splash screen with a Progress Dialog
I have a layout where a splash screen asks for input from a user,
My app has three main activity. Splash Activity Login Activity Menu Activity When I
My application splash screen is set to have one image fade in, then another,

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.