0

How can i recieve a bundle data from another activity to my widget activity class? This is my mainactivity code to send bundle data

Intent intent=new Intent(this,MyWidget.class);
    extras= new Bundle();
    extras.putString("FAJR", sfajr);
    extras.putString("ZUHR", sZuhr);
    extras.putString("ASR", sAsr);
    extras.putString("MAGRIB", sMagrib);
    extras.putString("ISHA", sIsha);
    intent.putExtras(extras);

But in my widget activity i cant recieve my bundle data? how can i get data in my widget activity?

Mostasim Billah
  • 4,447
  • 3
  • 19
  • 28

2 Answers2

0

Code in your Current Activity -

Intent intent=new Intent(this,MyWidget.class);
    extras= new Bundle();
    extras.putString("FAJR", sfajr);
    extras.putString("ZUHR", sZuhr);
    extras.putString("ASR", sAsr);
    extras.putString("MAGRIB", sMagrib);
    extras.putString("ISHA", sIsha);
    intent.putExtras(extras);
    startActivity(intent);

Code in your MyWidget class.

Bundle bundle = getIntent().getExtras();

//Extract the data…
String fajr= bundle.getString("FAJR");       
String zuhr= bundle.getString("ZUHR"); 
String asr= bundle.getString("ASR"); 
String magrib= bundle.getString("MAGRIB"); 
String isha= bundle.getString("ISHA"); 
Shoeb Siddique
  • 2,805
  • 1
  • 22
  • 42
0

Salam,

I am trying to help here. You may need to change your code to this :

Intent intent=new Intent(this,MyWidget.class);
//    extras= new Bundle();
    intent.putString("FAJR", sfajr);
    intent.putString("ZUHR", sZuhr);
    intent.putString("ASR", sAsr);
    intent.putString("MAGRIB", sMagrib);
    intent.putString("ISHA", sIsha);
//    intent.putExtras(extras);

And then in your other activity :

Bundle b = new Bundle();
b = getIntent().getExtras();
String fajr = b.getString("FAJR");
...

As per this so question Simple example for Intent and Bundle Voilà, hope this help.

Community
  • 1
  • 1
mourad
  • 667
  • 4
  • 11