Show Indeterminate Indicator when loading another Activity - android

I'm trying to show my Indeterminate Progress Indicator When a certain Card is being tapped.
I declared the indicator in my onCreate as follows
mSlider = Slider.from(mCardScroller);
mIndeterminate = mSlider.startIndeterminate();
Then in my onclick I have the following
mIndeterminate.show();
intent = new Intent(getApplicationContext(), CaptureActivity.class);
startActivityForResult(intent, REQUEST_CODE);
I want to show the progress indicator while the QR-Scan activity is being loaded since this takes a few seconds.
However with this the indicator doesn't show up at all. Is there a way to make sure the indicator is being shown while the called upon activity is loading?
When I take out the startActivityForResult() it does start the indicator so I'm pretty sure it has something to do with the lifecycle of the activity, but I'm not sure how I should go about it in this case.

I guess you should put the slider in CaptureActivity instead.
Your slider is hidden. From my understanding, you start the progress bar in the activity which is moved to the background. The whole activity cannot be seen not only the progress bar.
Try moving these code into onCreate of CaptureActivity
mSlider = Slider.from(mCardScroller);
mIndeterminate = mSlider.startIndeterminate();
mIndeterminate.show();

Related

Hide ProgressBar widget

I start an Activity1 from my MainActivity using Intent.
Activity1 takes quite a while to load (perhaps the Ads) so to reassure users that my app has not crushed I display a Circular ProgressBar in a linear layout id loading. To do this I turn Visibility of loading to Visible in the onClick event of a button.
Coming back from Activity1 I set visibility to Invisible like this:
ActivityResultLauncher<Intent> resultLaunch = registerForActivityResult(
new ActivityResultContracts.StartActivityForResult(),
result -> {
if(result.getResultCode()==111){
assert result.getData() != null;
String data= result.getData().getStringExtra("from");
if(data.equals("activity1")) {
loading.setVisibility(View.INVISIBLE);// back from Activity1 switch-off
loading
}
}
This works well but if user clicks the back button of his phone Progress Bar stays visible forever.
I have tried to set visibility in onResume() of MainActivity but it does not work.
I rather avoid to set up a timer. Any help?
#Override
public void onResume(){
super.onResume();
loading.setVisibility(View.INVISIBLE);// back from Activity1 switch-off loading
}
I turns out to work fine
This is happening because, the result code is not equals to 111. Change 111 with Result.Sucess and it will work fine. If you also want to hide the progress bar even if data is empty, add else statement and set visibility of progress bar to gone in there.

Dynamically show Activity as dialog

I have an Activity that I have already implemented sometime ago.
It involves around making a in app purchase, so all the logic is relatively self contained. it doesn't need to care about anything else.
Now, i wish to make that Activity to optionally show up in a dialog in some other activity. Is there a quick way to do that? I still need to keep the old behavior however, where the activity show up as a regular screen.
So is there someway that I could launch the activity with that make it show up as a dialog?
Thanks
You cant show activity as dialog.
Your options are:
1: Open the other activity with some boolean extra like "showDialog", true
Intent intent = new Intent(this, OtherActivity.class);
intent.putExtra("showDialog", true);
and in the other activity in (for example) onCreate:
Boolean showDialog = getIntent().getExtras().getBoolean("showDialog");
if (showDialog) {
// Code to show dialog
}
2: Create a DialogFragment and show it in your original activity. This custom DialogFragment you can use on both activities
https://guides.codepath.com/android/Using-DialogFragment
Probably your cleanest option depending on how complex your Activity is, is to create a new DialogFragment based on your current activity.
A DialogFragment is basically a Fragment, so has a relatively similar set of lifecycle callbacks to your Activity so it shouldn't be too difficult to re-work as a DialogFragment.
If the in-app purchase framework has specific callback requirements with an Activity then you will need to take that into account.
Another separate option would be to mock the appearance of a Dialog, by creating an Activity that may be transparent around the border of the main content.
Just Inflate the layout one button click on onCreate Method.
WhAT I WILL SUGGEST IS try alert box and in place of normal layout inflate you activity layout .
these might help
The easiest way to do that is to apply a dialog theme to the activity:
<activity android:theme="#style/Theme.AppCompat.Dialog" />
Or in the code:
#Override
protected void onCreate(Bundle savedInstanceState) {
setTheme(R.style.Theme_AppCompat_Dialog);
super.onCreate(savedInstanceState);
setContentView(R.layout.test);
}
You can customize parameters of the theme in styles.xml, e.g. dim enabled/disabled, click outside behavior.
The crucial point is to perform setTheme() before super.onCreate(), because Theme is immutable, once set through super.onCreate() it cannot be mutated later.

start new activity on swipe of a image

I have a layout with image view . On SWIPE LEFT of layout I want to call a new activity.
Intent right_intent = new Intent();
right_intent.setClass(this, mainScreenClass.class);
right_intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(right_intent);
I am able to do this but calling of new activity is taking long pause. Which seems nothing is going on for fraction of second.
Can i do anything so that swipe of image calls new activity without any time.
why do you use Intent.FLAG_ACTIVITY_CLEAR_TOP? this will clear the stack of the activity
Are you using gallery view kind of control, Delay may happen if your downloading images from server and showing that in this imageview so when you swipe an image next image starts loading in next imageview from server. If this is the case you can try to use fragments, So that gallery view and another new activity you calling can be made as separate fragments and can be attached to Single FragmentActivity.
So that while swiping image in single fragment you can replace it with another fragment(your new actiivty contents) or use indicator.onPageSelected(arg0) to keep the another fragment selected(your new activity contents), it will be having somne reduced delay when compared of calling new Actiivty

is it possible to display progress bar switching between one activity to another activity in android

Is it possible to show progress bar when switching from activity to another.please help me
You will have to show the progress bar in the second activity because the first activity will be hidden and wouldn't show up anyway.
try this!!!!
ProgressDialog pd = new ProgressDialog(FirstActivity.this);
//use this before calling intent
pd.setMessage("Processing...");
pd.show();
//call this in onResume of firstActivity
pd.dismiss();

Android DialogFragment progress bar

I've searched everywhere and I can't find a solution to this problem.
Basically I have a login screen and I'm trying to get a progress spinner to show up while it's logging in to the server (via a thread), and then dismiss it after the login is successful. It has to work while changing orientations.
I am using DialogFragment with the Android compatibility package to make a progress bar (can't find any documentation on it, only for basic\alert dialog) because showDialog() is deprecated now. Right now I just show a custom message box as a login spinner.
In Summary:
How can I set up a Progress spinner with DialogFragment.
How can I dismiss it in another thread after orientation changes.
For showing a progress spinner, just override DialogFragment.onCreateDialog() in your dialog fragment like this (no need for overriding onCreateView()):
#Override
public Dialog onCreateDialog(final Bundle savedInstanceState) {
final ProgressDialog dialog = new ProgressDialog(getActivity());
//
dialog.setTitle(R.string.login_title);
dialog.setMessage(getString(R.string.login_message));
dialog.setIndeterminate(true);
dialog.setCancelable(false);
// etc...
return dialog;
}
As for dismissing that dialog fragment from somewhere else, you'll need to get a hold of FragmentManager (from inside your next FragmentActivity or Fragment) and call popBackStack() on it (if you don't do any other fragment transaction in the meantime).
If there's more steps/fragment transactions between your progress dialog fragment and the next activity, you'll probably need one of the other popBackStack(...) methods that take an ID or tag to pop everything up to your progress dialog fragment off the stack.
I know this is old question but I want to share much better solution for this
According to Android Development Protip:
"Stop using ProgressDialog,Inline indicators are your friend"
As Roman Nurik states:
This one's quick. Stop using ProgressDialog and other modal loading
indicators. They're extremely interruptive and annoying, especially
when:
You see one every time you switch tabs.
You can't Back out of them.
They say "Please wait." No thanks, I'd rather just uninstall.
Either show loading indicators inline with your content (e.g.
http://developer.android.com/training/animation/crossfade.html) or better yet, load small amounts of data in the
background so that you minimize the need to even show a loading
indicator.
More about progress & activity in the design guidelines.

Categories

Resources