Note that there are some explanatory texts on larger screens.

plurals
  1. POHaving two activities with Mainctivity causes the back button to not work properly
    text
    copied!<p>I have a MainActivity and I am posting partial code here:</p> <pre><code>@Override public boolean onOptionsItemSelected(MenuItem item) { // Handle item selection switch (item.getItemId()) { case R.id.action_quit: moveTaskToBack(true); return true; case R.id.action_help: //display the help activity Intent myIntent = new Intent( this, ShowHelp.class); startActivityForResult(myIntent, 0); return true; case R.id.action_about: //display the about window //aboutApp(); return true; default: return super.onOptionsItemSelected(item); } } public void aboutApp() { // custom dialog final Dialog dialog = new Dialog(this); dialog.setContentView(R.layout.about); dialog.setTitle("About TollCulator"); TextView textViewAbout = (TextView) dialog.findViewById(R.id.tvContents); textViewAbout.setText("About: "); textViewAbout.append("\n\tTollCulator - Toll Calculator"); textViewAbout.setMovementMethod(new ScrollingMovementMethod()); Button btnCloseIt = (Button) dialog.findViewById(R.id.btnOk); // if button is clicked, close the custom dialog btnCloseIt.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { dialog.dismiss(); } }); ImageView iv1 = (ImageView) dialog.findViewById(R.id.imgFB); iv1.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { Uri uri = Uri.parse("https://www.facebook.com/PagesByZ");); Intent intent = new Intent(Intent.ACTION_VIEW, uri); dialog.cancel(); startActivity(intent); } }); dialog.show(); } </code></pre> <p>ShowHelp.class partial code here which is an Activity on it's own:</p> <pre><code>@Override public boolean onOptionsItemSelected(MenuItem item) { switch(item.getItemId()) { case 16908332: Intent myIntent = new Intent(getApplicationContext(), MainActivity.class); startActivityForResult(myIntent, 0); //finish(); } return super.onOptionsItemSelected(item); } @Override public void onBackPressed() { // do something on back. Intent myIntent = new Intent(getApplicationContext(), MainActivity.class); startActivityForResult(myIntent, 0); //finish(); return; } </code></pre> <p>Now when i choose <code>action_help</code> from the menu it opens the ShowClass Activity and I can press the back button and it brings me back to MainActivity without any problem.</p> <p>Now If I choose <code>action_about</code> the About Dialog pops up and If I click on the icon within the Dialog the following pops up: <img src="https://i.stack.imgur.com/uZzA7.png" alt="enter image description here"></p> <p>At this time If I decide to press BACK, instead of closing the pop and displaying my About Dialog, I am just taken to the Homescreen.</p> <p><strong>Commenting the <code>finish();</code> method in ShowClass allows me to click the BACK button from the "Complete action using" But instead of taking me to the MainActivity, it takes me to ShowClass from there I can press the Back button again to come back to MainActivity. So as long as I choose <code>action_help</code> first, pressing back brings me back to the ShowHelp.</strong></p> <p>When the Complete action using pops up from the About Dialog, I set up a Log, and it's on the onPause() state and if I did not run ShowHelp in the beginning, my App goes directly to onStop() and onDestroy().</p> <p>Please help me fix the issue.</p> <p>To test it, I created a demo without the ShowHelp class with just the dialog and By pressing back button, the Complete actiong using dialog closes and then pressing back again closes the About Dialog. So I am not sure what is going on.</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