Skip to content Skip to sidebar Skip to footer

Getintent() Wrote In Red

I am trying to pass string from main activity to another class extends from services. I send it like this from onCreate method at main: Intent phoneintent = new Intent(MainActivity

Solution 1:

Intentphoneintent=newIntent(MainActivity.this, AlarmServic.class);
StringphoneN= phoneNumber.getText().toString();
phoneintent.putExtra("PhoneNumber",phoneN );
startService(phoneintent);// If its a Service

And Retrieve in Service as

publicintonStartCommand(Intent intent, int flags, int startId){

     String phoneNumber= intent.getStringExtra("PhoneNumber");
     ...........
}

Solution 2:

use bundle in 1st Activity

Bundle bundle=new Bundle();bundle.putString("key",phone);Intent intent=new Intent(?.this,?.class);intent.putExtras(bundle);startActivity(intent);

//2nd Screen

Bundle bundle=new Bundle(); if(bundle!=null){ String boom=bundle.getString("key"); }

//stored the value //do whatever

Post a Comment for "Getintent() Wrote In Red"