简体   繁体   中英

Android 'complete action using' back button press handling

My android app uses

Intent i = new Intent(Intent.ACTION_VIEW, uri);
            i.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
            startActivity(i);

to begin the twitter OAuth process. This code is triggered by a button press. I would like the button to change to a progress bar when it is pressed, which I have implemented.

When the new activity is started, the user is prompted with a 'complete action using' dialog, and if the user presses the back key while this dialog box is showing, they are returned to my activity. I would like to handle this event and turn my progress bar back to a button - how can I do this?

When the user clicks back, the onResume() method of the fragment is called. Because of this, I can change the button back to the normal style.

You can override the method onBackPressed(). Inside it, you can do what you want, so when you press the back button it will be trigered. An example for your case would be to put this code on your activity:

@Override
public void onBackPressed()
{
     super.onBackPressed();  // this will do the normal behavior of the back pressed.
     //in this case, it will close the dialog
     button.setVisibility(View.VISIBLE);
     progressBar.setVisibility(View.GONE);
}

I hope it helps =)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM