0

I am using fragments in android. And I want to implement a functionality i.e. if a notification arrives on device then a particular action will he happened on fragment.

What I have done to implement functionality I am doing that if a notification arrives I stored it in shared preference and I am running a handler in my fragment for every second which means when a notification arrives I store value in shared preference and based on it my handler runs and hit web service but I am facing one problem that is if I run code for very first time then it runs perfectly after that if i switch to another activity and then came to that fragment and then a notification arrives my fragment will not be refreshed. Please help me in this regard.Thanks in advance.

code of gcm intent class

         if(msgg.contains("has been cancelled due to following reason"))
        {
            editor.putString("cancelOrder", "1");
            String[] a1 = msgg.split("#");
            String a2=a1[0];
            String a3 = a1[1];

            String[] part = a3.split(" ");
            String part1 = part[0];

            editor.putString("cancelOrderidnew", part1);
            editor.commit();
            msg = msgg;
        }

code for my fragment

     private final Runnable runforneworder = new Runnable() {
    @Override
    public void run() {


     String   cancelOrdernew = sp.getString("cancelOrderidnew", null);

        if (cancelOrdernew != null)
        {
            connectToDatabase();
        }

        handler.postDelayed(runforneworder, 1000);
    }
};


public void connectToDatabase() {



 new GetOrders().execute(new Config().newOrd, id);
}
Mukesh Mishra
  • 241
  • 1
  • 3
  • 12

0 Answers0