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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:43:31+00:00 2026-05-27T15:43:31+00:00

In my application, I am using onCreate(), for initialize of application, onStart() and onResume().

  • 0

In my application, I am using onCreate(), for initialize of application, onStart() and onResume().

According to activity life cycle all of mentioned methods are running sequentially. In onStart() method, I have a custom dialog that when runs I take user id and password after that I send them to server and server sends me a token.

Then after taking Token I should go next step which is onResume().

but the problem is after showing dialog from onStart(), activity will go to next cycle, onResumme(). How can I say to android, “Hey guy, please don’t go to next cycle until I take token from server”?

This is my code:

@Override
    protected void onStart() {
        super.onStart();
        Log.i("MA_onStart", "Activity is abut to start...");

    .
    .
    .

        if(!isOnline())
        dialogWarning.show();


        if(!isTokenValid())
            dialog.show();
    }
}

In this code, I call isTokenValid(). If don’t have token then I will show a dialog to take user id and password. I want activity doesn’t go to next stage until I get token. I can add while loop to wrap

if(!isTokenValid()) dialog.show();

and set a flag for breaking the loop. I can set the flag when user click yes button in dialog but I afraid that if process takes some seconds, Android kill my process and application. what is your suggestion?

Thanks

==========>
Update

I changed the code to this

gotoNextCycle = true;
            while(gotoNextCycle)
            if(!isTokenValid())
                dialog.show();

and put gotoNextCycle = false; when user clicked yes button in dialog. As I expected, the application crashed.

  • 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-27T15:43:31+00:00Added an answer on May 27, 2026 at 3:43 pm

    What is the problem if you let Android continue with the cycle..
    i mean what will happen if onResume() is called?

    You should not wait in onStart() or onResume() for responses from server.
    This would lead to ANR as you have observed.
    You can update your app so that once you get response from server with valid token, you can refresh your view or data shown in the activity.
    Maybe, let us know what information you are showing in the Activity, we can try to help you with a way to handle invalid Token case (fetch Token from server and update the information).

    EDIT

    you can refer the following code:

    @Override
    protected void onResume() {
        super.onResume();
    
        if(isTokenValid()) {
           doProcess();
        } else {
           showDialog(USER_ID_DLG);
        }
      }
    
    private void doProcess() {
       .... 
    }
    

    in onClick() of the dialog (yes button) start a Tread or AsyncTask to fetch Token from server. Meanwhile you can show a Progress dialog (“Loading… please wait” kinds).
    Once you get response from server, in the Thread or AsyncTask dismiss this progress dialog and then call doProcess().

    I assume you show some information in this activity to user based on the server response/Token. So once the Progress dialog is dismissed, your doProcess() can update the views.

    If the authentication fails, then you can call finish() on the Activity after showing some Toast to user about the failure.

    Also make sure you call setCancelable(false) on the Progress dialog.

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

Sidebar

Related Questions

I have an Android service, created in OnCreate of first Activity of the application
Hi I am using the Application::onCreate to put my initialisation code of my app,
I am writing an application that communicates using sockets. I have a server running
In My application i am using two list view's in one activity, one for
Hai i have a application using background service.its running clearly.If my mobile is switch
I have a web application using ASP.NET 2.0 and I want to know if
I am developing an application using MVC Preview 5. I have used typed views.
An older application using System.Web.Mail is throwing an exception on emails coming from hr@domain.com
In my ASP.NET application using InProc sessions, Session_End calls a static method in another
I developing ASP.NET application using a Swedish version of Windows XP and Visual studio

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.