I want to pass the arraylist of all the phonenumbers created into the background service so that I can message them all at once when a shake gesture is triggered.
This is the MainActivity
snippet where I use the intent.putExtra()
method to pass my arraylist into the service.
SensorService sensorService = new SensorService();
Intent intent = new Intent(this, sensorService.getClass());
if(!isMyServiceRunning(sensorService.getClass())){
startService(intent);
intent.putExtra("ContactNumberList", Contact_Number);
Toast.makeText(this, "Starting Service", Toast.LENGTH_SHORT).show();
}
and this is the snippet for assigning the passed arraylist. in the SensorService
DatabaseHelper db = new DatabaseHelper(SensorService.this);
ArrayList<String> Contact_id, Contact_Name, Contact_Number;
ArrayList<String> phonenumber = new ArrayList<String>();
phonenumber = (ArrayList<String>)getIntent().getSerializableExtra("ContactNumberList");
I get the compiler error Cannot resolve method 'getIntent()'
I wanted to know if there is a better way to pass the created arraylist from the MainActivity
to my background service ?
2
Answers
Try removing
(ArrayList<String>)
type cast. It should give you the option to importgetIntent
after that. If you need to type cast it, you can do it after you have the value.You need two things: