I am passing value through Bundle as you can see in my code.
Now, I want its value in another activity onCreate()
. I tried it to get its value but it is showing nullpointerexception.
Please help me solve the problem.
Bundle bundle = new Bundle();
String url = "http://www.google.com";
bundle.putString("url", url);
Intent myIntent = new Intent(context, NotificationService.class);
myIntent.putExtras(bundle);
context.startService(myIntent);
Get Value code :
if (!getIntent().getExtras().getString("url").contains(null)) {
// Do something
}
//put value in intent like this
// get value from bundle like this
Replace
startService(...)
- >startActivity(...)
And Also replace
TO
Intent serviceIntent = new Intent(YourService.class.getName()); serviceIntent.putExtra("url", "www.google.com"); context.startService(serviceIntent);
When the service is started its onStartCommand() method will be called so in this method you can fetch the value (url) from the intent object
public int onStartCommand (Intent intent, int flags, int startId){
String userID = intent.getStringExtra("url");
return START_STICKY; }
Because you put your strings inside a bundle
And then put the bundle as an extra to the intent
In the begining You have to strip the bundle from extras
Then get Strings from yourbundle
String value = bundle.getString("request");
try this
and on another activity get it like