1
int seqno = 0; 
seqno++;

String seq = String.valueOf(seqno);
Firebase postRef = rootRef.child("employee");
Map<String, String> post1 = new HashMap<String, String>();

post1.put("Seqno", seq);

i want to store the seq number in firebase, each time when I try to add seq number to firebase it has to increament and add. eg: 1,2,3..

My problem is because of initializing seqno to 0 , every time it gets initialized and add as 1,1,1...

Firebase data

i have to retrieve only the path field from sub-trees. how can I do that?

can anyone help me to solve this ?

Priyanka
  • 33
  • 8
  • 3
    More context is likely needed to be able to answer this. If you want a static counter you can declare a static field in your class and increment that instead. – froderik Feb 17 '16 at 08:18
  • Define `seqno` as global/instance variable, instead of local. Or pull last added seq number from firebase and assign it to `seqno` instead of just `int seqno = 0;` – ankhzet Feb 17 '16 at 08:19
  • When is 'every time'? Who is calling this code? When? How often? –  Feb 17 '16 at 08:20
  • does this help ? http://stackoverflow.com/q/28915706/4290096 – Arun Xavier Feb 17 '16 at 08:20

2 Answers2

0

Enclose the code that adds the SeqNo to firebase inside a function...and call it... Keep the initialization statement outside... something like..

private static int seqno = 0; 


public void AddSquence(int seqno)
{
String seq = String.valueOf(seqno);
Firebase postRef = rootRef.child("employee");
Map<String, String> post1 = new HashMap<String, String>();
post1.put("Seqno", seq);

    if(seqno > max)
      {
       System.exit(0);
      }
   else
    {
    AddSquence(seqno+1);
    }

    }
yoga ranjan
  • 125
  • 2
  • 11
0

You can always make "seqno" as a class member: field of the class like this:

public class MyClass{
  private int seqno;
  ....
}
Lazar Lazarov
  • 2,412
  • 4
  • 26
  • 35