为什么id每次都在同一部手机上改变? Firebase数据库

时间:2018-05-02 15:00:52

标签: java android firebase firebase-realtime-database

enter image description here首先,我想说我的英语不是很好,但我希望这不是问题(我希望)。所以我写了一个代码,“应该”从我的应用程序的用户获取用户ID,但每次都是 firebase获取同一手机上的其他ID可以有人帮我解决这个问题吗? 如果您需要更多信息,请在评论中写下。先感谢您。这是我的代码。

EditText editTextName;
Button buttonAdd;
Spinner spinnerGenres;

DatabaseReference databaseArtists;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_one_cent);

    databaseArtists = FirebaseDatabase.getInstance().getReference("prousers");

    editTextName = (EditText) findViewById(R.id.editTextName);
    buttonAdd = (Button) findViewById(R.id.buttonAddArtist);
    spinnerGenres = (Spinner) findViewById(R.id.spinnerGenres);

    buttonAdd.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
         addArtist();
        }
    });
}

private void addArtist(){
    String name = editTextName.getText().toString().trim();
    String genre = spinnerGenres.getSelectedItem().toString();

    if (!TextUtils.isEmpty(name)){

        String id = databaseArtists.push().getKey();

        Artist artist = new Artist(id, name, genre);

        databaseArtists.child(id).setValue(artist);

        Toast.makeText(this, "You are a pro user :D", Toast.LENGTH_LONG).show();

        finish();
        System.exit(0);
    }else{
        Toast.makeText(this, "Something's wrong", Toast.LENGTH_LONG).show();
    }
}

}

也是这个

public Artist(){

}

public Artist(String artistId, String artistName, String artistGenre) {
    this.artistId = artistId;
    this.artistName = artistName;
    this.artistGenre = artistGenre;
}

public String getArtistId() {
    return artistId;
}

public String getArtistName() {
    return artistName;
}

public String getArtistGenre() {
    return artistGenre;
}

}

0 个答案:

没有答案