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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T04:15:51+00:00 2026-06-09T04:15:51+00:00

I saw many solution to maintain AlertDialog and most of them doesn’t work probably

  • 0

I saw many solution to maintain AlertDialog and most of them doesn’t work probably when screen dim down. but this which i made works fine is there any other light weight way to do that , I want to use it inside Fragment from ACL .

 public class Test extends Activity {

    AlertDialog dialog;
    boolean dialog_should_be_shown = false;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Button btn = new Button(this);
        btn.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View arg0) {
                createDialog();
            }
        });
        setContentView(btn);
        if (savedInstanceState != null) {
            dialog_should_be_shown = savedInstanceState.getBoolean("flag",
                    false);
        }
    }

    private void createDialog() {
        dialog = new AlertDialog.Builder(Test.this).setMessage("HEllo")
                .setCancelable(true).create();
        dialog.show();
    }

    @Override
    protected void onSaveInstanceState(Bundle outState) {

        super.onSaveInstanceState(outState);
        outState.putBoolean("flag", dialog_should_be_shown);
    }

    @Override
    protected void onResume() {
        super.onResume();
        if (dialog_should_be_shown) {
            createDialog();
        }
    }

    @Override
    protected void onPause() {
        super.onPause();
        if (dialog != null && dialog.isShowing()) {
            dialog_should_be_shown = true;
            dialog.dismiss();
        } else {
            dialog_should_be_shown = false;
        }
    }

    @Override
    protected void onStop() {
        super.onStop();

    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_test, menu);
        return true;
    }
}

UPDATE :
I dont want to retain Framgnet in memory.

  • 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-09T04:15:52+00:00Added an answer on June 9, 2026 at 4:15 am

    use DialogFragment instead, it is included on the support library and you can retain it using setRetainInstance(true),

    http://developer.android.com/reference/android/app/DialogFragment.html

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

Sidebar

Related Questions

I saw many questions about json in stackoverflow. Most of them are unanswered or
I saw many similar questions here but their answers don't work for me by
I saw many threads with this tittle, but no one really speak about reuse
I saw many questions asking 'how' to unit test in a specific language, but
On the lolcode website I saw many references to various lolcode interpreters. But is
I saw many question addressing this issue but still i have some doubts... I
I look up a lot through this problem while i saw many post abt
Fastest way to uniqify a list in Python without preserving order? I saw many
I saw % in many codes. Can you explain to me its purpose or
I saw in many application like Zara, Zara Home, D&G.. that instead of using

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.