'How to add loader gif between activities in android java
How do I make loading gif of 3 dots between activities that I already built? after pressing continue button I want loader to be showen for 5 sec and then redirect to the next activity.
Solution 1:[1]
First, you have to create and show dialog on button click.
AlertDialog alert = builder.create();
alert.show();
After this, you have to use handler to show dialog for 5 sec. and after that you have to hide dialog and call the intent.
new Handler(Looper.myLooper()).postDelayed(new Runnable() {
@Override
public void run() {
alert.hide();
startActivity(new Intent(this,SecondActivity.class));
}
},5*1000);
Solution 2:[2]
You could create a progress dialog
protected void showProgressDialog(String message) {
_ProgressDialog.setMessage(message);
_ProgressDialog.setCanceledOnTouchOutside(false);
_ProgressBusy = true;
_ProgressDialog.show();
}
then have a countdown timer that dismisses it once time's up
CountDownTimer mCountDownTimer = new CountDownTimer(6000, 1000) {
@Override
public void onTick(long millisUntilFinished) {
showProgressDialog("Rebooting...");
}
@Override
public void onFinish() {
hideProgressDialog();
}
};
mCountDownTimer.start();
the hide is just a dismiss
protected void hideProgressDialog() {
_ProgressDialog.dismiss();
_ProgressBusy = false;
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Rupesh Rathod |
| Solution 2 | NotSOSMartie |
