如何使更新数据真正好用?

时间:2018-08-28 15:59:33

标签: java android

我正在尝试在Firebase实时数据库中使用更新方法。请有人帮我弄清楚如何正确工作吗?

更新广告方法:-

private void UpdateAdvertisement(String tuitionimage, String tuitioname)
{
    HashMap userMap = new HashMap();
        userMap.put("adstuitionimage", tuitionimage);
        userMap.put("adstuitioname", tuitioname);
    updateAdvertisement.updateChildren(userMap).addOnCompleteListener(new OnCompleteListener()
    {
        @Override
        public void onComplete(@NonNull Task task)
        {
            if (task.isSuccessful())
            {
                SendUserToViewAdsActivity();
                Toast.makeText(EditAdsActivity.this, "Advertisement has been updated successfully!", Toast.LENGTH_SHORT).show();
            }

            else
            {
                Toast.makeText(EditAdsActivity.this, "Error occured: Failed to save the updating advertisement data. Please try again.", Toast.LENGTH_LONG).show();
            }
        }
    });
}

1 个答案:

答案 0 :(得分:0)

为此,我们可以使用Intent类:

在您已有数据的第一个活动中,

例如:String data = edit_text.getText().toString();

所以您可以写:

Intent i = new Intent(this, SecondActivity.class);
i.putExtra("your_key", "" + data);   // Collected from EditText or any other source
...........
........... (You can have similar putExtras as many as you want)
startActivity(i);

然后,在您的“第二个活动”课程中,

onCreate()方法中,写

Intent i = getIntent();
String data = i.getStringExtra("your_key"); // This key must be the same as from previous activity
............. (Similarly you can do for all)

最后,在您希望在Firebase中更新的地方使用该数据。

希望它应该能工作。