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

  • Home
  • SEARCH
  • 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 8929169
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T08:36:51+00:00 2026-06-15T08:36:51+00:00

I have just started Android development. I have a very simple project. I have

  • 0

I have just started Android development. I have a very simple project. I have a button and a textview. When I click the button, the text of the textView changes and button is disabled. This part is working fine. However I want the button to maintain its state (disabled state) if I press home on phone (Escape on keyboard) and go back to my app. But in my case, Button gets enabled every time I press home and get back to my app. Here is the code

package com.mypack.textmanipulation;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.*;

public class MainActivity extends Activity {

    private Button btnChangeText;
    private boolean check;

    @Override
    protected void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        btnChangeText = (Button)findViewById(R.id.btnChangeText);
        check = true;

        setButtonOnClickInterface();

    }

    @Override
    protected void onResume()
    {
        super.onResume();
        checkButtonIsEnabled();
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) 
    {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }

    private void setButtonOnClickInterface()
    {

        btnChangeText.setOnClickListener(new View.OnClickListener() 
        {

            @Override
            public void onClick(View v) 
            {

                    // TODO Auto-generated method stub
                    TextView txtView = (TextView)findViewById(R.id.textView1);
                    txtView.setText("Text Changed");
                    btnChangeText.setEnabled(false);
                    check = false;
            }
        });

    }

    private void checkButtonIsEnabled()
    {
        if (check)
        {
            btnChangeText.setEnabled(true);

        }
        else
        {
            btnChangeText.setEnabled(false);
        }
    }


}

Suggestions are welcome.
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-15T08:36:52+00:00Added an answer on June 15, 2026 at 8:36 am

    Well just found the solution. I was exiting the app instead of pausing it. Actually i was presing the ESC button on the keyboard to go back to HOME screen which is actually equivalent to the BACK button in Android and in my case, i guess, the app was exiting, so every time i tapped the app icon again, onCreate event is been called instead of onResume.

    BTW HOME button on Keyboard acts as Android HOME button.

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

Sidebar

Related Questions

I am just started Android application development. Here i have a simple Activity which
I have just started learning Android and thought of a simple project to help
So I just started Android development, and I've already hit a wall. I have
I have just started using RSpec and I copied the very simple test on
I have just started doing Android development on Mac OS X in Eclipse. When
I have just started connecting android app with php My file works very fine
I have just started with Android with the usual Hello World project template in
I have just started android development in eclipse with android and am trying to
I just started development for Android, and I am stuck with this code: public
I just started with PhoneGap development and have my first sample android app running

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.