I'm new to asking questions here so any advice about that will be appreciated...but to my problem:
I'm trying to switch from one activity to another, where I'll show some data from the server. I'm pulling the data from server via AsyncTask but there is black screen showing between the activities, when the download is longer. I already tried to put the AsyncTask from onCreate() to onStart() but no change there.
New activity:
public class SalesMenu extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
setContentView(R.layout.sales_menu);
setProgressBarIndeterminateVisibility(true);
super.onCreate(savedInstanceState);
}
@Override
protected void onStart() {
List<HashMap<String, Object>> result = null;
AsyncTask<Void, Boolean, List<HashMap<String, Object>>> aTask = new AsyncSearchRead(
"sale.order",
new Object[0],
new String[] {"name"},
this).execute();
try {
result = aTask.get();
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
}
Log.d("test", (result!=null ? result.toString() : "nothing"));
super.onStart();
}
}
My AsyncTask:
public class AsyncSearchRead extends AsyncTask<Void, Boolean, List<HashMap<String, Object>>> {
String mModel;
boolean mCount;
Integer mOffset;
Integer mLimit;
String mOrder;
boolean mReverseOrder;
Object[] mConditions;
String[] mFields;
Activity parentActivity;
public AsyncSearchRead(String model, boolean count, Integer offset, Integer limit,
String order, boolean reverseOrder, Object[] conditions, String[] fields,
Activity activity) {
mModel = model;
mCount = count;
mOffset = offset;
mLimit = limit;
mOrder = order;
mReverseOrder = reverseOrder;
mConditions = conditions;
mFields = fields;
parentActivity = activity;
}
@Override
protected List<HashMap<String, Object>> doInBackground(Void... params) {
Long[] ids;
List<HashMap<String, Object>> results;
//Downloading the data
ids = SetServer.connection.search(mModel, mCount, mOffset, mLimit, mOrder, mReverseOrder, mConditions);
results = SetServer.connection.read(mModel, ids, mFields);
return results;
}
@Override
protected void onPostExecute(List<HashMap<String, Object>> result) {
parentActivity.setProgressBarIndeterminateVisibility(false);
}
}
When I did not turn visibility off onPostExecute it kept spinning after showing the activity but it's only shown after the loading.
How can I get it to show the activity and only after that start to load the data and show some progress bar/loader?
Thanks for any help.