目前我正试图通过firebase的详细信息来填充我的活动。我希望首先打开活动,然后在自动填充之前显示微调器,同时获取详细信息。现在发生的事情是它尝试在打开页面之前加载活动细节,从而使UI延迟。这是我的代码
这是在创建
上完成的waitForDetails();
ObscuredSharedPreferences mySubscription = ObscuredSharedPreferences.getPrefs(getApplicationContext(), "MySubscription", MODE_PRIVATE);
final ObscuredSharedPreferences.Editor editorSub = mySubscription.edit();
String end = mySubscription.getString("EndSub", null);
String last = mySubscription.getString("LastSub", null);
endSubView.setText(end);
lastSubView.setText(last);
subDiffView.setText(dateConvert()+" "+getString(R.string.days_manage));
subDiffView.setGravity(Gravity.CENTER);
spin.setVisibility(View.GONE);
layout.setVisibility(View.VISIBLE);
这是waitForDetails方法
private void waitForDetails(){
final Handler handler = new Handler();
final Runnable r = new Runnable() {
public void run() {
ObscuredSharedPreferences pref = ObscuredSharedPreferences.getPrefs(getApplicationContext(), "MyPref", MODE_PRIVATE);
final ObscuredSharedPreferences.Editor editor = pref.edit();
final String userName = pref.getString("Username", null);
ObscuredSharedPreferences mySubscription = ObscuredSharedPreferences.getPrefs(getApplicationContext(), "MySubscription", MODE_PRIVATE);
final ObscuredSharedPreferences.Editor editorSub = mySubscription.edit();
editorSub.clear();
editorSub.apply();
Firebase ref = new Firebase(Config.FIREBASE_URL);
ref.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot snapshot) {
User user = snapshot.child(userName).getValue(User.class);
String endSub = user.getEndSubscription();
String lastSub = user.getLastSubscription();
editorSub.clear();
editorSub.apply();
editorSub.putString("EndSub", endSub);
editorSub.putString("LastSub", lastSub);
editorSub.apply();
}
@Override
public void onCancelled(FirebaseError firebaseError) {
System.out.println("The read failed: " + firebaseError.getMessage());
}
});
handler.postDelayed(this, 1000);
}
};
handler.postDelayed(r, 1000);
}
答案 0 :(得分:0)
使用AsyncTask ..
声明AsyncTask,然后只显示AsyncTask的ProgressDialog <label>
<input type="radio" ng-model="groups.group" value="1">
Admin
</label><br/>
<label>
<input type="radio" ng-model="groups.group" value="2">
User
</label><br/>
<label>
<input type="radio" ng-model="groups.group" value="3">
Viewer
</label><br/>
方法。耗费时间和应用程序会冻结诸如从 $scope.createUser = function(user, groups){
groups.group = "2";
};
中的链接检索数据。检索到的帖子链接是否在asyncTask的onPreExecute()
方法中工作,并关闭doInBackground()
。 AsyncTask在与主活动不同的线程上运行,因此应用程序不会冻结。
您可以像
一样调用AsyncTask类 onPostExecute()
// ASYNC TASK
ProgressDialog