2
저는 현재 데이터베이스로 firebase를 사용하고 있지만 onDataChange
메서드에서 변수를 가져 와서 전역 변수에 할당하면 안드로이드 응용 프로그램을 개발하고 있습니다. onDataChange
메서드에서 해당 변수를 호출하면 null이 아닙니다.null 변수가 onDataChange 메서드에서 벗어났습니다
public class PositionateMarkerTask extends AsyncTask {
public ArrayList<Location> arrayList= new ArrayList<>();
public void connect() {
//setting connexion parameter
final Firebase ref = new Firebase("https://test.firebaseio.com/test");
Query query = ref.orderByChild("longitude");
//get the data from the DB
query.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
//checking if the user exist
if(dataSnapshot.exists()){
for (DataSnapshot userSnapshot : dataSnapshot.getChildren()) {
//get each user which has the target username
Location location =userSnapshot.getValue(Location.class);
arrayList.add(location);
//if the password is true , the data will be storaged in the sharedPreferences file and a Home activity will be launched
}
}
else{
System.out.println("not found");
}
}
@Override
public void onCancelled(FirebaseError firebaseError) {
System.out.println("problem ");
}
});
}
@Override
protected Object doInBackground(Object[] params) {
connect();
return null;
}
@Override
protected void onPostExecute(Object o) {
super.onPostExecute(o);
System.out.println("the firs long is"+arrayList.get(0).getLongitude());
}
}
당신이 당신의 데이터베이스 구조를 제공 할 수있는 일을 바랍니다? – Wilik