Results 1 to 3 of 3
  1. #1
    Darkyere is offline Member
    Join Date
    Aug 2009
    Posts
    4
    Rep Power
    0

    Question Change a public boolean value from another activity

    I have created a Public boolean in main window. that when its true will finish the main activity.

    the question is now how i change that value from another activity.

    i have spend over 24 hours on this problem and must accept i cant seem to figure it out myself:/

    this is my code from the screen that need to be closed.


    Java Code:
    public static Boolean CanIClose = false;
        @Override
        public void onResume(){
            super.onResume();
            Intent intent = getIntent();
            if (CanIClose.equals(true)){
            NewShoppingListMainScreen.this.finish();
            }
        }
    and this is the code from the window that i need to change the boolean value from.

    Java Code:
    public void dlgexitbtn(View view){
            Intent intent = new Intent(this, NewShoppingListMainScreen.class);
            intent.putExtra("true", NewShoppingListMainScreen.CanIClose);
            NewShoppingListMainScreen.CanIClose.equals(true);
            this.finish();
    
        }

    My quess is i need to use intent to pass the value or change it. But im fairly new and cant seem to figure it out:/

    Hope that i can be helped and best regards from Mark
    Last edited by Darkyere; 10-02-2012 at 11:56 PM.

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,956
    Rep Power
    19

    Default Re: Change a public boolean value from another activity

    Java Code:
    NewShoppingListMainScreen.CanIClose.equals(true);
    That's not setting the value.
    That's simply comparing CanIClose with 'true'.
    Try:
    Java Code:
    NewShoppingListMainScreen.CanIClose = Boolean.TRUE;
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  3. #3
    Darkyere is offline Member
    Join Date
    Aug 2009
    Posts
    4
    Rep Power
    0

    Default Re: Change a public boolean value from another activity

    Ty kindly for this very simple way to do it :) it worked exactly as intended and closed my main window too :)

    Ty again
    Mark

Similar Threads

  1. Replies: 0
    Last Post: 10-01-2011, 04:14 AM
  2. Replies: 3
    Last Post: 09-13-2011, 12:01 AM
  3. Replies: 1
    Last Post: 09-12-2011, 02:09 AM
  4. Why wont my boolean variable change?
    By equal in forum New To Java
    Replies: 8
    Last Post: 02-22-2011, 10:43 PM
  5. Replies: 5
    Last Post: 06-26-2009, 03:03 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •