G
G
geron2016-01-18 12:18:53
Android
geron, 2016-01-18 12:18:53

How to make a progressbar on top of the window, so that the previous activity is dimmed and made inactive?

Hello! I develop android applications. Applications are actively working with the network. At the time of data loading, I made a ProgressDialog. I don’t really like this approach, I would like to make the previous activity dimmed or hidden and only the progressbar in the middle would be visible. I can't find a suitable solution. Can you please tell me how this can be done?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
C
Copperfield, 2016-01-18
@Copperfield

You need a DialogFragment .
This is a normal snippet, but with additional "dialog" methods like show , cancel , setCancelable .

J
jinnerrer, 2016-01-19
@jinnerrer

I have something like this in one project:
load data happens through async task:
private class checkForUpdates extends AsyncTask {
Context mContext;
public checkForUpdates(Context context) {
mContext = context.getApplicationContext();
}
@Override
protected void onPreExecute() {
super.onPreExecute();
loaderActivity = new LoaderActivity();
}
@Override
protected Void doInBackground(Void... params) {
final ParseQuery query = ParseQuery.getQuery("GameSettings");
query.getFirstInBackground(new GetCallback() {
@Override
public void done(ParseObject parseObject, ParseException e) {
isUpdating = parseObject.getBoolean("updating");
Intent i = new Intent(mContext, MainMenuActivity.class);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
mContext.startActivity(i);
}
else
{
new getGameItems(context).execute();
}
}
});
return null;
}
@Override
protected void onPostExecute(Void result) {
}
}
Thus, I launch the date loading method from one activity. Upon completion of the latter, a transition occurs to another activity. I think it will not be difficult at all to make this scheme out of this: Run the load method at the same time show a view indicating the loading of content (something), then upon completion of the async task, we return to the first activity (which launched this method). At the same time, we make the activity containing the progress bar (I would customize it for beauty) transparent. It's such a dirty hack, but it works. There are opponents of launching activities from non-activities classes, who say that there is a memory leak. But these are all special cases, and if you build everything correctly, you do not have to deal with memory leak troubles.
What else? async task with a loader, of course, does not have to be hidden in a separate non-activation class (it is quite possible to place it in an activity), but it’s more convenient for me personally))
If anything, ask. I am also interested in communication and development)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question