我能够构建apk,我有LoginActivity.java,SignupActivity.java,StoreNameAndType.java和User.java,RetrieveDataActivity.java。
我还能够将apk部署到我的Android手机中,并且这些应用程序与布局登录活动,注册活动,商店名称和类型活动完美配合。
在我在登录布局中登录后,retrieveDataActivity的布局。但是当它转移到布局retrieveataactivity时,它将显示小于10秒的布局UI并且崩溃。
为什么我无法在firebase中检索用户的大量数据?我按照YouTube上的教程但布局崩溃了。我的代码有问题吗?
我以user-d( 3wgmOhWlUUcyoBQXKZWnhw3K7Ik2 )登录。
这是我的数据库树。我想从用户ID( yKlWu19vhqQXfL2tDlBNfMSduMe2 )中检索所有信息。
{
"3wgmOhWlUUcyoBQXKZWnhw3K7Ik2" : {
"name" : "MAMA",
"type" : "P"
},
"yKlWu19vhqQXfL2tDlBNfMSduMe2" : {
"location" : {
"latitude" : 3.0537728,
"longitude" : 101.4826099
},
"name" : "AYAH NAN",
"type" : "D"
}
}
这是我的规则
{
"rules": {
".read": "auth != null",
".write": "auth != null"
}
}
这是我的RetrivedataActivity.java
public class RetrieveDataActivity extends AppCompatActivity implements
ValueEventListener {
private DatabaseReference databaseReference, mNameReference,
mTypeReference, mLocationReference, mLatReference, mLongReference;
private TextView mNameView, mTypeView, mLatView, mLongView;
@Override
public void onCreate( Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_retrievedata);
databaseReference = FirebaseDatabase.getInstance().getReference().child("yKlWu19vhqQXfL2tDlBNfMSduMe2");
mNameReference = databaseReference.child("name");
mTypeReference = databaseReference.child("type");
mLocationReference = databaseReference.child("location");
mLatReference = mLocationReference.child("latitude");
mLongReference = mLocationReference.child("longitude");
mNameView = (TextView) findViewById(R.id.textViewName);
mTypeView = (TextView) findViewById(R.id.textViewType);
mLatView = (TextView) findViewById(R.id.textViewLat);
mLongView = (TextView) findViewById(R.id.textViewLong);
}
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
if(dataSnapshot.getValue(String.class)!=null)
{
String key = dataSnapshot.getKey();
if(key.equals("name"))
{
String name = dataSnapshot.getValue(String.class);
mNameView.setText(name);
}else if(key.equals("type"))
{
String type = dataSnapshot.getValue(String.class);
mTypeView.setText(type);
}else if(key.equals("latitude"))
{
String lat = dataSnapshot.getValue(String.class);
mLatView.setText(lat);
}else if(key.equals("longitude"))
{
String log = dataSnapshot.getValue(String.class);
mLongView.setText(log);
}
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
@Override
protected void onStart() {
super.onStart();
mNameReference.addValueEventListener(this);
mTypeReference.addValueEventListener(this);
mLatReference.addValueEventListener(this);
mLongReference.addValueEventListener(this);
}
}