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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T10:17:17+00:00 2026-06-11T10:17:17+00:00

In my Android App, user first lands on Login Activity. I am checking network

  • 0

In my Android App, user first lands on Login Activity. I am checking network availability. if network is not available, I want to stop the excision further.

Is is something we need to work on the code level or we have something available like activity.cancel() or return null on the Activity to process next code. Note that I do NOT want to close the Activity. I just want to alert the user that network is not available.

Here is the code:

       public void onClick(View v) {
    if ( v.getId() == R.id.btnLogin ) {

        if ( Utilities.isNetworkAvailable(this) ) {
            mIsNetworkAvailable = true;
        } 

        if ( mIsNetworkAvailable ) {
            username = ((EditText) findViewById(R.id.username)).getText().toString().trim();
            password = ((EditText) findViewById(R.id.password)).getText().toString().trim();
        }

        // If U/P is empty, do NOT process anything, just display the alert and stop.
        if ( username.length() == 0 || password.length() == 0) {
            Utilities.showAlert("Please enter username and password", this);

            // HOW TO STOP THE EXECUTION HERE
        } else if ( !mIsNetworkAvailable ) {
            Utilities.showAlert("Internet connection is not availble in your device.", this);
            // HOW TO STOP THE EXECUTION HERE
        }

        // If not any of the above, proceed.

        User userobj = new User();
        userobj.setUsername( username );
        userobj.setPassword( password );

        TaskHandler handler = new TaskHandler(getString(R.string.server_uri) + "Verify/", userobj, LoginActivity.this);
    }
}

EDIT

The above code is in onClick (Login Button). What I want to achieve is, when user clicks on Login button, if network is not available, I need to show the alert and stop further process. If its successful, I need to open the next activity.

This is regular flow like we do elsewhere. I know, we can wrap up the entire code in if-else block. But I am wondering, if there is a way to stop the execution with a call like finish().

Note that, I do NOT want to destroy/close the activity. The activity should remain intact so user can keep trying, probably after turning on the network.

  • 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-11T10:17:19+00:00Added an answer on June 11, 2026 at 10:17 am

    Try this. Just return if the constraint is not satisfied. Shown below…

    .... .....
    .... .....
    if ( username.length() == 0 || password.length() == 0) {
            Utilities.showAlert("Please enter username and password", this);
    
            return;
        } else if ( !mIsNetworkAvailable ) {
            Utilities.showAlert("Internet connection is not availble in your device.", this);
           return;
        }
    
    
        User userobj = new User();
        userobj.setUsername( username );
        userobj.setPassword( password );
    .... .....
    .... .....
    

    Hope it helps you!

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

Sidebar

Related Questions

I want authenticate user in my android app through google login and then dispaly
I have a dialog in an Android app that I don't want the user
I have facebook login setup in my android app. When the user clicks login
I am developing an Android app and I want to detect when the user
On my android app, first time when app runs, user must type a license.
I'm planning my first real android app and I want it to be a
In my Android app, when a user tries to transition from one activity to
I have an android app where the user paints, moves and reshapes some objects
I have an android app which let the user to submit a form ,
I have an android app which gives the user the option of loading a

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.