2017-12-31 206 views
-3

私は自分のアプリケーションを最小限に抑えて、そのアクティビティを実行すると動作しますが、別のアクティビティからそのアクティビティに来たときに動作しません。私のonCreateで私はプロジェクトでアクティビティを持っていますが、アクティビティを開始するときにfirebaseにノードがありますが、オンラインにする必要がありますが動作しません。

auth = FirebaseAuth.getInstance(); 
     currentUser = auth.getCurrentUser(); 

     db = FirebaseDatabase.getInstance(); 
     userRef = db.getReference().child("Users").child(auth.getCurrentUser().getUid()); 

     if(currentUser == null) { 
      sendToStart(); 
     } else { 
      userRef.child("online").setValue("true"); 
     } 

以下のような私はあまりにも私のONSTART方法で同じことを持っていますが、動作していません。
私を助けてもらえますか?

答えて

0

バックグラウンド・サービスでこのステートメントを実行すると、ノードを更新するようにしてください。

public class MyService extends Service { 

    @Override 
    public int onStartCommand(Intent intent, int flags, int startId) { 
     //TODO do something useful 

    auth = FirebaseAuth.getInstance(); 
    currentUser = auth.getCurrentUser(); 

    db = FirebaseDatabase.getInstance(); 
    userRef = db.getReference().child("Users").child(auth.getCurrentUser().getUid()); 

    if(currentUser == null) { 
     sendToStart(); 
    } else { 
     userRef.child("online").setValue("true"); 
    } 


     return Service.START_NOT_STICKY; 
    } 

    @Override 
    public IBinder onBind(Intent intent) { 
    //TODO for communication return IBinder implementation 
    return null; 
    } 
} 


Intent i= new Intent(context, MyService.class); 
context.startService(i); 
+0

どのようにすればいいですか? – Hemal

+0

私は追加しました。 –

関連する問題