Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Declare a global boolean variable <code>chooserIsShowing</code>:</p> <pre><code>boolean chooserIsShowing; </code></pre> <p>Set it to true here:</p> <pre><code>ImageView iv1 = (ImageView) dialog.findViewById(R.id.imgFB); iv1.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { // set the flag chooserIsShowing = true; Uri uri = Uri.parse("https://www.facebook.com/PagesByZ");); Intent intent = new Intent(Intent.ACTION_VIEW, uri); dialog.cancel(); startActivity(intent); } }); </code></pre> <p>Change the overriden <code>onBackPressed()</code> method:</p> <pre><code>@Override public void onBackPressed() { if (!chooserIsShowing) { // do something on back. Intent myIntent = new Intent(getApplicationContext(), MainActivity.class); startActivityForResult(myIntent, 0); finish(); } // remove the flag chooserIsShowing = false; return; } </code></pre> <p><strong>Edit 1:</strong></p> <p>Declare <code>dialog</code> as a global variable:</p> <pre><code>Dialog dialog; </code></pre> <p>Change <code>aboutApp()</code>:</p> <pre><code>public void aboutApp() { dialog = new Dialog(this); .... } </code></pre> <p>Override <code>onKeyDown(int, KeyEvent)</code> method in MainActivity:</p> <pre><code>@Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK) { if (dialog != null &amp;&amp; dialog.isShowing()) { dialog.dismiss(); return true; } } return super.onKeyDown(keyCode, event); } </code></pre> <p>You can remove <code>chooserIsShowing</code> as its not required.</p> <p><strong>Final Solution:</strong></p> <p>A <code>noHistory</code> flag was defined for this activity in the manifest. Removing that and fixing <code>onBackPressed()</code> method of <code>ShowHelp</code> resolved the issue.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload