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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T19:04:03+00:00 2026-05-31T19:04:03+00:00

my problem is that when i try to set the text of service1 and

  • 0

my problem is that when i try to set the text of service1 and service1Health in my code below, The text is not being set. Any ideas as to why this is happening? service1Name and service1HealthValue both have valid string values.

public void onClick(View v) 
{

    switch(v.getId())
    {
    case R.id.loginButton:
        String[] values = new String[2];
        String usernameText = ((TextView) activity.findViewById(R.id.usernameTextBox)).getText().toString();
        String passwordText = ((TextView) activity.findViewById(R.id.txtPasswordField)).getText().toString();

        if (usernameText.length()==0 || passwordText.length()==0)
            Toast.makeText(activity, "Please fill in both username and password fields", Toast.LENGTH_SHORT).show();
        else
        {
            Toast.makeText(activity, "Connecting to server", Toast.LENGTH_LONG).show();
            String loginResult = Server.login(usernameText,passwordText);

            values = loginResult.split(",");

            Intent i = new Intent(activity,Home.class);
            activity.startActivity(i);
            activity.setContentView(R.layout.home);

            String service1Name = Server.getServices("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
            String service1HealthValue = Server.getHealth("myservice","xxxxxxxxxxxxxxxxxxxxxxxxxxx");


            TextView service1= ((TextView) activity.findViewById(R.id.serviceName1));
            TextView service1Health= ((TextView) activity.findViewById(R.id.service1Health));


            service1.setText(service1Name);
            service1Health.setText(service1HealthValue);

        }
        break;
    }
}
  • 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-31T19:04:04+00:00Added an answer on May 31, 2026 at 7:04 pm

    When you call activity.startActivity(i);, it launches a new activity, so any code after this, including activity.setContentView(R.layout.home); will not be reached, so none of these TextViews will get set. If you want to set these values in the new activity, you should add them to the Intent, then reopen them in the onCreate method of the new Activity. So for example, in your current Activity:

    Intent i = new Intent(activity,Home.class);
    i.putExtra("service1Name", Server.getServices("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"));
    i.putExtra("service1HealthValue", Server.getHealth("myservice","xxxxxxxxxxxxxxxxxxxxxxxxxxx"));
    activity.startActivity(i);
    

    And in the onCreate method of Home.java, add the following:

    setContentView(R.layout.home);
    Intent i = getIntent();
    if (i != null) {
        //This means that the intent passed here was found
        String serviceName1 = i.getStringExtra("serviceName1");
        String service1HealthValue = i.getStringExtra("service1HealthValue");
        TextView service1= ((TextView) activity.findViewById(R.id.serviceName1));
        TextView service1Health= ((TextView) activity.findViewById(R.id.service1Health));
        service1.setText(service1Name);
        service1Health.setText(service1HealthValue);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im currently facing the problem that when i try to set focus on some
Greetings, what is the problem that when I try to set credentials for my
I have a strange problem that I could not solve. When I try to
I have this simple problem. I'll try to explain with a sample code An
My problem is that I have to set a variable in a try statement
The problem is that when I try doing multiple animations they all happen the
i try to read Data from an Oracle-Database. The problem is that in some
I have a problem with javascript, im calling an ajax method that returns this
I am using uploadify and my problem is that the files are not uploading.
I'm able to get text using HTMLCleaner from website. The problem is that when

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.