Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I think you should, when the <code>Activity</code> picture is displayed, try to call the <code>onBackPressed</code> method. </p> <pre><code>// back button pressed method @Override public void onBackPressed() { super.onBackPressed(); // new intent to call an activity that you choose Intent intent = new Intent(this, NewActivity.class); startActivity(intent); // finish the activity picture this.finish(); } </code></pre> <p>If you don't want to call an external <code>Activity</code>, you can hide the layout calling by the <code>Intent</code> as below: </p> <pre><code>// back button pressed method @Override public void onBackPressed() { super.onBackPressed(); // your layout with the picture is displayed, hide it if(MySecondView.getVisibility() == View.VISIBLE) MySecondView.setVisibility(View.Gone); // display the layout that you want MyDefaultView.setVisibility(View.VISIBLE); } </code></pre> <p>As I said below, try with a <strong>boolean</strong> that you initialize to false at the beginning of your <code>Class</code>. When you start the <code>Intent.ACTION_VIEW</code>, make this boolean to true: </p> <pre><code>public class Foo extends Activity { private boolean isSms = false; // some stuff Intent intent = new Intent(Intent.ACTION_VIEW); intent.setType("vnd.android-dir/mms-sms"); // ... startActivity(intent); // make your boolean to true isSms = true; // create the onBackPressed method @Override public void onBackPressed() { // check if the user is on the sms layout if(isSms) // do something else // do something else like finish(); your activity } } </code></pre> <p>Or you can try to use the <code>onKeyDown</code> method (see here: <a href="http://developer.android.com/reference/android/view/View.html#onKeyDown%28int,%20android.view.KeyEvent%29" rel="nofollow noreferrer">onKeyDown (int keyCode, KeyEvent event)</a>) as below: </p> <pre><code>public boolean onKeyDown(int keyCode, KeyEvent event) { if(keyCode==KeyEvent.KEYCODE_BACK &amp;&amp; event.getRepeatCount()==0) { // dome some stuff return true; } return super.onKeyDown(keyCode, event); } </code></pre> <p>You can see the diffence between these two methods here: <a href="https://stackoverflow.com/a/3558613/2668136">onBackPressed() not working</a> and on the website that I talk in the comments below.<br> Hope this will be useful. </p> <hr> <p><strong>UPDATE:</strong><br> A better way should make an startActivityForResult to start the Intent.ACTION_VIEW: </p> <pre><code>startActivityForResult(intent, 1); </code></pre> <p>And then, you return the cancel code like this: </p> <pre><code>protected void onActivityResult(int requestCode, int resultCode, Intent data) { if(requestCode != 1 &amp;&amp; resultCode == RESULT_CANCELED) { // do something } } </code></pre> <p>This is @FunkTheMonk, just above, who tells the good choice!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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