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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T12:26:53+00:00 2026-06-09T12:26:53+00:00

within my main activity I have the following code: EditText usernameText; EditText passwordText; public

  • 0

within my main activity I have the following code:

EditText usernameText;
EditText passwordText;
public void sendLogin (View loginview){
    Intent i = new Intent(this, NetworkService.class);
    startService(i);
}

Currently, this just sends an intent to the NetworkService, which is handled as follows (truncated):

public class NetworkService extends IntentService {

    public NetworkService() {
        super("NetworkService");
    }

    protected void onHandleIntent(Intent i) {

        /* HTTP CONNECTION STUFF */

        String login = URLEncoder.encode("Username", "UTF-8") + "=" + URLEncoder.encode("XXX", "UTF-8");
        login += "&" + URLEncoder.encode("Password", "UTF-8") + "=" + URLEncoder.encode("XXX", "UTF-8"); 
    }
}

Now, what I need to figure out, is how to pass those usernameText and passwordText values through to the NetworkService into the ‘XXX’, but ALSO within the NetworkService, I intend (no pun intended), to have it handle multiple intents from various places, one from a login, one from retrieving some information on users using the logon token, for instance.
It’s where all my networking will be contained. I was instructed this was the best practise within android applications, to keep the networking separate.

My question is: What is the best way of sending those two variables to the NetworkService and also how, within the onHandleIntent of the NetworkService, do I separate the code to only do what I’m asking it to (login, fetch user information, fetch location data etc)?

Sorry if the answer is a simple one, but I’m very new to application programming.

Thanks

  • 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-09T12:26:55+00:00Added an answer on June 9, 2026 at 12:26 pm
    public void sendLogin (View loginview){
        Intent i = new Intent(this, NetworkService.class);
        i.putExtra("username", usernameText.getText().toString());
        i.putExtra("password", passwordText.getText().toString());
        startService(i);
    }
    

    Then in your IntentService:

    @Override
        protected void onHandleIntent(Intent intent) {
        String username = intent.getStringExtra("username");
        String password = intent.getStringExtra("password");
        ...
    }
    

    IntentServices are designed to handle several requests sent to it. In other words, if you keep sending intents using startService(intent), your NetworkService will keep getting its onHandleIntent method called. Under the hood, it has a queue of intents that it will work through until it is finished. So if you keep sending intents the way you are currently, but with certain flags set through the putExtra methods, then you can detect what your NetworkService should do and act appropriately. e.g. set a boolean extra to your intent called login, in your intentservice look for that flag being set via intent.getBooleanExtra("login"). If true, do your login stuff, else look for other flags you set.

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

Sidebar

Related Questions

I have a main activity which calls a child one via Intent I =
My situation is following. I have one Activity that contains three main parts. At
I have an Android app with a main tab activity, and several activities within
I have 2 internal div's within a main div JSfiddle - http://jsfiddle.net/uwdnH/ Illustration -
I have 2 files, main.html and search.php . Within the main.html page, there is
I am designing a potal framework and I have multiple portlets(divs) within the main
Please enlighten this flex noob. I have a remoteobject within my main.mxml. I can
I have 2 classes within same package. Both classes have main method in them.
In my android list page/activity I have a 2 text fields a main and
I have my main Activity, it starts with a custom SurfaceView called DrawView being

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.