Inconsistent behavior for Firebase Realtime Database
up vote
0
down vote
favorite
I try to update the data in Firebase Realtime Database through Android app. It will only occasionally work after I open the app and wait for some time. Most of the time it does not work. In my case, working mean the data is updated in cloud. I am wondering why it work sometimes and do not work sometimes. There is no error or warning in Logcat. Once it works, it will continue to work until the app is restarted.
DbHelper class
public class DbHelper {
static final String TAG = "ttt";
int count = 0;
private static FirebaseDatabase database = FirebaseDatabase.getInstance();
private static DatabaseReference myRef = database.getReference("message");
TextView tv;
public DbHelper(final TextView tv){
this.tv = tv;
myRef.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
String text = dataSnapshot.getValue(String.class);
tv.setText(text);
Log.d(TAG, "Value is: " + text);
}
@Override
public void onCancelled(DatabaseError databaseError) {
Log.w(TAG, "Failed to read value.", databaseError.toException());
}
});
}
public void testing(){
myRef.setValue("test"+count++);
}
}
MainActivity
public class MainActivity extends AppCompatActivity {
TextView textTesting;
DbHelper dbHelper;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
textTesting = (TextView)findViewById(R.id.text_testing);
dbHelper = new DbHelper(textTesting);
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
dbHelper.testing();
}
});
}
}
Added
DatabaseReference connectedRef = FirebaseDatabase.getInstance().getReference(".info/connected");
connectedRef.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot snapshot) {
boolean connected = snapshot.getValue(Boolean.class);
if (connected) {
Log.d(TAG, "connected");
} else {
Log.d(TAG, "not connected");
}
}
@Override
public void onCancelled(DatabaseError error) {
System.err.println("Listener was cancelled");
}
});
Logcat
11-14 20:26:58.956 19329-19384/? V/FA: Connection attempt already in progress
11-14 20:26:58.956 19329-19384/? V/FA: Connection attempt already in progress
11-14 20:26:58.961 19329-19384/? V/FA: Activity resumed, time: 167270724
11-14 20:26:58.986 19329-19384/? D/FA: Connected to remote service
11-14 20:26:59.001 19329-19329/? I/Timeline: Timeline: Activity_idle id: android.os.BinderProxy@34fb88b7 time:15941479
11-14 20:26:59.006 19329-19384/? V/FA: Processing queued up service tasks: 4
11-14 20:26:59.056 19329-19336/? I/art: Ignoring second debugger -- accepting and dropping
11-14 20:26:59.541 19329-19329/? D/ViewRootImpl: ViewPostImeInputStage ACTION_DOWN
11-14 20:26:59.631 19329-19329/? D/ttt: Value is: test0
11-14 20:27:02.366 19329-19329/? D/ViewRootImpl: ViewPostImeInputStage ACTION_DOWN
11-14 20:27:02.451 19329-19329/? D/ttt: Value is: test1
11-14 20:27:04.166 19329-19384/? V/FA: Inactivity, disconnecting from the service
11-14 20:28:07.721 19329-19329/? D/FA: Service connection suspended
android firebase firebase-realtime-database
|
show 8 more comments
up vote
0
down vote
favorite
I try to update the data in Firebase Realtime Database through Android app. It will only occasionally work after I open the app and wait for some time. Most of the time it does not work. In my case, working mean the data is updated in cloud. I am wondering why it work sometimes and do not work sometimes. There is no error or warning in Logcat. Once it works, it will continue to work until the app is restarted.
DbHelper class
public class DbHelper {
static final String TAG = "ttt";
int count = 0;
private static FirebaseDatabase database = FirebaseDatabase.getInstance();
private static DatabaseReference myRef = database.getReference("message");
TextView tv;
public DbHelper(final TextView tv){
this.tv = tv;
myRef.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
String text = dataSnapshot.getValue(String.class);
tv.setText(text);
Log.d(TAG, "Value is: " + text);
}
@Override
public void onCancelled(DatabaseError databaseError) {
Log.w(TAG, "Failed to read value.", databaseError.toException());
}
});
}
public void testing(){
myRef.setValue("test"+count++);
}
}
MainActivity
public class MainActivity extends AppCompatActivity {
TextView textTesting;
DbHelper dbHelper;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
textTesting = (TextView)findViewById(R.id.text_testing);
dbHelper = new DbHelper(textTesting);
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
dbHelper.testing();
}
});
}
}
Added
DatabaseReference connectedRef = FirebaseDatabase.getInstance().getReference(".info/connected");
connectedRef.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot snapshot) {
boolean connected = snapshot.getValue(Boolean.class);
if (connected) {
Log.d(TAG, "connected");
} else {
Log.d(TAG, "not connected");
}
}
@Override
public void onCancelled(DatabaseError error) {
System.err.println("Listener was cancelled");
}
});
Logcat
11-14 20:26:58.956 19329-19384/? V/FA: Connection attempt already in progress
11-14 20:26:58.956 19329-19384/? V/FA: Connection attempt already in progress
11-14 20:26:58.961 19329-19384/? V/FA: Activity resumed, time: 167270724
11-14 20:26:58.986 19329-19384/? D/FA: Connected to remote service
11-14 20:26:59.001 19329-19329/? I/Timeline: Timeline: Activity_idle id: android.os.BinderProxy@34fb88b7 time:15941479
11-14 20:26:59.006 19329-19384/? V/FA: Processing queued up service tasks: 4
11-14 20:26:59.056 19329-19336/? I/art: Ignoring second debugger -- accepting and dropping
11-14 20:26:59.541 19329-19329/? D/ViewRootImpl: ViewPostImeInputStage ACTION_DOWN
11-14 20:26:59.631 19329-19329/? D/ttt: Value is: test0
11-14 20:27:02.366 19329-19329/? D/ViewRootImpl: ViewPostImeInputStage ACTION_DOWN
11-14 20:27:02.451 19329-19329/? D/ttt: Value is: test1
11-14 20:27:04.166 19329-19384/? V/FA: Inactivity, disconnecting from the service
11-14 20:28:07.721 19329-19329/? D/FA: Service connection suspended
android firebase firebase-realtime-database
4
What do you mean by "it does not work"? What happens? Do you see any errors or messages in Logcat?
– Grimthorr
Nov 13 at 13:55
Is there any reason why you put Firebase operations in a separate class instead of using instant creations?
– Cool Guy CG
Nov 13 at 13:59
1
@SamTew Do you have disk persistence ("offline capabilities") enabled? If the data is updated locally but never synced to Firebase: it sounds like a network issue.
– Grimthorr
Nov 13 at 14:15
1
@SamTew Check Logcat for any messages from Firebase such asD/FA: Connected to remote service
to see if your app is actually connecting to the Firebase services.
– Grimthorr
Nov 13 at 14:36
1
@Grimthorr I found out the reason. The DNS used by ISP is the problem. Change to Google DNS solved my problem
– SamTew
Nov 18 at 1:27
|
show 8 more comments
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I try to update the data in Firebase Realtime Database through Android app. It will only occasionally work after I open the app and wait for some time. Most of the time it does not work. In my case, working mean the data is updated in cloud. I am wondering why it work sometimes and do not work sometimes. There is no error or warning in Logcat. Once it works, it will continue to work until the app is restarted.
DbHelper class
public class DbHelper {
static final String TAG = "ttt";
int count = 0;
private static FirebaseDatabase database = FirebaseDatabase.getInstance();
private static DatabaseReference myRef = database.getReference("message");
TextView tv;
public DbHelper(final TextView tv){
this.tv = tv;
myRef.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
String text = dataSnapshot.getValue(String.class);
tv.setText(text);
Log.d(TAG, "Value is: " + text);
}
@Override
public void onCancelled(DatabaseError databaseError) {
Log.w(TAG, "Failed to read value.", databaseError.toException());
}
});
}
public void testing(){
myRef.setValue("test"+count++);
}
}
MainActivity
public class MainActivity extends AppCompatActivity {
TextView textTesting;
DbHelper dbHelper;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
textTesting = (TextView)findViewById(R.id.text_testing);
dbHelper = new DbHelper(textTesting);
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
dbHelper.testing();
}
});
}
}
Added
DatabaseReference connectedRef = FirebaseDatabase.getInstance().getReference(".info/connected");
connectedRef.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot snapshot) {
boolean connected = snapshot.getValue(Boolean.class);
if (connected) {
Log.d(TAG, "connected");
} else {
Log.d(TAG, "not connected");
}
}
@Override
public void onCancelled(DatabaseError error) {
System.err.println("Listener was cancelled");
}
});
Logcat
11-14 20:26:58.956 19329-19384/? V/FA: Connection attempt already in progress
11-14 20:26:58.956 19329-19384/? V/FA: Connection attempt already in progress
11-14 20:26:58.961 19329-19384/? V/FA: Activity resumed, time: 167270724
11-14 20:26:58.986 19329-19384/? D/FA: Connected to remote service
11-14 20:26:59.001 19329-19329/? I/Timeline: Timeline: Activity_idle id: android.os.BinderProxy@34fb88b7 time:15941479
11-14 20:26:59.006 19329-19384/? V/FA: Processing queued up service tasks: 4
11-14 20:26:59.056 19329-19336/? I/art: Ignoring second debugger -- accepting and dropping
11-14 20:26:59.541 19329-19329/? D/ViewRootImpl: ViewPostImeInputStage ACTION_DOWN
11-14 20:26:59.631 19329-19329/? D/ttt: Value is: test0
11-14 20:27:02.366 19329-19329/? D/ViewRootImpl: ViewPostImeInputStage ACTION_DOWN
11-14 20:27:02.451 19329-19329/? D/ttt: Value is: test1
11-14 20:27:04.166 19329-19384/? V/FA: Inactivity, disconnecting from the service
11-14 20:28:07.721 19329-19329/? D/FA: Service connection suspended
android firebase firebase-realtime-database
I try to update the data in Firebase Realtime Database through Android app. It will only occasionally work after I open the app and wait for some time. Most of the time it does not work. In my case, working mean the data is updated in cloud. I am wondering why it work sometimes and do not work sometimes. There is no error or warning in Logcat. Once it works, it will continue to work until the app is restarted.
DbHelper class
public class DbHelper {
static final String TAG = "ttt";
int count = 0;
private static FirebaseDatabase database = FirebaseDatabase.getInstance();
private static DatabaseReference myRef = database.getReference("message");
TextView tv;
public DbHelper(final TextView tv){
this.tv = tv;
myRef.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
String text = dataSnapshot.getValue(String.class);
tv.setText(text);
Log.d(TAG, "Value is: " + text);
}
@Override
public void onCancelled(DatabaseError databaseError) {
Log.w(TAG, "Failed to read value.", databaseError.toException());
}
});
}
public void testing(){
myRef.setValue("test"+count++);
}
}
MainActivity
public class MainActivity extends AppCompatActivity {
TextView textTesting;
DbHelper dbHelper;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
textTesting = (TextView)findViewById(R.id.text_testing);
dbHelper = new DbHelper(textTesting);
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
dbHelper.testing();
}
});
}
}
Added
DatabaseReference connectedRef = FirebaseDatabase.getInstance().getReference(".info/connected");
connectedRef.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot snapshot) {
boolean connected = snapshot.getValue(Boolean.class);
if (connected) {
Log.d(TAG, "connected");
} else {
Log.d(TAG, "not connected");
}
}
@Override
public void onCancelled(DatabaseError error) {
System.err.println("Listener was cancelled");
}
});
Logcat
11-14 20:26:58.956 19329-19384/? V/FA: Connection attempt already in progress
11-14 20:26:58.956 19329-19384/? V/FA: Connection attempt already in progress
11-14 20:26:58.961 19329-19384/? V/FA: Activity resumed, time: 167270724
11-14 20:26:58.986 19329-19384/? D/FA: Connected to remote service
11-14 20:26:59.001 19329-19329/? I/Timeline: Timeline: Activity_idle id: android.os.BinderProxy@34fb88b7 time:15941479
11-14 20:26:59.006 19329-19384/? V/FA: Processing queued up service tasks: 4
11-14 20:26:59.056 19329-19336/? I/art: Ignoring second debugger -- accepting and dropping
11-14 20:26:59.541 19329-19329/? D/ViewRootImpl: ViewPostImeInputStage ACTION_DOWN
11-14 20:26:59.631 19329-19329/? D/ttt: Value is: test0
11-14 20:27:02.366 19329-19329/? D/ViewRootImpl: ViewPostImeInputStage ACTION_DOWN
11-14 20:27:02.451 19329-19329/? D/ttt: Value is: test1
11-14 20:27:04.166 19329-19384/? V/FA: Inactivity, disconnecting from the service
11-14 20:28:07.721 19329-19329/? D/FA: Service connection suspended
android firebase firebase-realtime-database
android firebase firebase-realtime-database
edited Nov 14 at 13:59
asked Nov 13 at 13:42
SamTew
343321
343321
4
What do you mean by "it does not work"? What happens? Do you see any errors or messages in Logcat?
– Grimthorr
Nov 13 at 13:55
Is there any reason why you put Firebase operations in a separate class instead of using instant creations?
– Cool Guy CG
Nov 13 at 13:59
1
@SamTew Do you have disk persistence ("offline capabilities") enabled? If the data is updated locally but never synced to Firebase: it sounds like a network issue.
– Grimthorr
Nov 13 at 14:15
1
@SamTew Check Logcat for any messages from Firebase such asD/FA: Connected to remote service
to see if your app is actually connecting to the Firebase services.
– Grimthorr
Nov 13 at 14:36
1
@Grimthorr I found out the reason. The DNS used by ISP is the problem. Change to Google DNS solved my problem
– SamTew
Nov 18 at 1:27
|
show 8 more comments
4
What do you mean by "it does not work"? What happens? Do you see any errors or messages in Logcat?
– Grimthorr
Nov 13 at 13:55
Is there any reason why you put Firebase operations in a separate class instead of using instant creations?
– Cool Guy CG
Nov 13 at 13:59
1
@SamTew Do you have disk persistence ("offline capabilities") enabled? If the data is updated locally but never synced to Firebase: it sounds like a network issue.
– Grimthorr
Nov 13 at 14:15
1
@SamTew Check Logcat for any messages from Firebase such asD/FA: Connected to remote service
to see if your app is actually connecting to the Firebase services.
– Grimthorr
Nov 13 at 14:36
1
@Grimthorr I found out the reason. The DNS used by ISP is the problem. Change to Google DNS solved my problem
– SamTew
Nov 18 at 1:27
4
4
What do you mean by "it does not work"? What happens? Do you see any errors or messages in Logcat?
– Grimthorr
Nov 13 at 13:55
What do you mean by "it does not work"? What happens? Do you see any errors or messages in Logcat?
– Grimthorr
Nov 13 at 13:55
Is there any reason why you put Firebase operations in a separate class instead of using instant creations?
– Cool Guy CG
Nov 13 at 13:59
Is there any reason why you put Firebase operations in a separate class instead of using instant creations?
– Cool Guy CG
Nov 13 at 13:59
1
1
@SamTew Do you have disk persistence ("offline capabilities") enabled? If the data is updated locally but never synced to Firebase: it sounds like a network issue.
– Grimthorr
Nov 13 at 14:15
@SamTew Do you have disk persistence ("offline capabilities") enabled? If the data is updated locally but never synced to Firebase: it sounds like a network issue.
– Grimthorr
Nov 13 at 14:15
1
1
@SamTew Check Logcat for any messages from Firebase such as
D/FA: Connected to remote service
to see if your app is actually connecting to the Firebase services.– Grimthorr
Nov 13 at 14:36
@SamTew Check Logcat for any messages from Firebase such as
D/FA: Connected to remote service
to see if your app is actually connecting to the Firebase services.– Grimthorr
Nov 13 at 14:36
1
1
@Grimthorr I found out the reason. The DNS used by ISP is the problem. Change to Google DNS solved my problem
– SamTew
Nov 18 at 1:27
@Grimthorr I found out the reason. The DNS used by ISP is the problem. Change to Google DNS solved my problem
– SamTew
Nov 18 at 1:27
|
show 8 more comments
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53282362%2finconsistent-behavior-for-firebase-realtime-database%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
4
What do you mean by "it does not work"? What happens? Do you see any errors or messages in Logcat?
– Grimthorr
Nov 13 at 13:55
Is there any reason why you put Firebase operations in a separate class instead of using instant creations?
– Cool Guy CG
Nov 13 at 13:59
1
@SamTew Do you have disk persistence ("offline capabilities") enabled? If the data is updated locally but never synced to Firebase: it sounds like a network issue.
– Grimthorr
Nov 13 at 14:15
1
@SamTew Check Logcat for any messages from Firebase such as
D/FA: Connected to remote service
to see if your app is actually connecting to the Firebase services.– Grimthorr
Nov 13 at 14:36
1
@Grimthorr I found out the reason. The DNS used by ISP is the problem. Change to Google DNS solved my problem
– SamTew
Nov 18 at 1:27