I want to pass an ArrayList File to a service to visualize its data but it is not possible for me in the line that receives the information, the program stops, this is the code
Method to send it
public void SendToService(){
Intent service=new Intent(MainActivity.this,ForegroundService.class);
if(ForegroundService.IS_SERVICE_RUNNING){
AdapterService=recibidor_file;
service.setAction(Constantes.ACTION.DATA_ACTION);
ForegroundService.IS_SERVICE_RUNNING=true;
service.putExtra("key",AdapterService);
startService(service);
}
}
This is the service
public int onStartCommand(Intent intent,int flags,int StarId){
recibidor=(ArrayList)intent.getExtras().getSerializable("key");
titulo=String.valueOf(recibidor);
}
Thank you in advance, this problem has a big head where I'm looking for getIntent
talk but it does not work within a Servcio
Logcat
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.a7860k.reproductor, PID: 8787
java.lang.RuntimeException: Unable to start service com.example.a7860k.reproductor.ForegroundService@384fbbd1 with Intent { act=com.example.a7860k.reproductor.action.startforeground cmp=com.example.a7860k.reproductor/.ForegroundService (has extras) }: java.lang.ClassCastException: java.lang.String cannot be cast to java.util.ArrayList
at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:2911)
at android.app.ActivityThread.access$2100(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1401)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Caused by: java.lang.ClassCastException: java.lang.String cannot be cast to java.util.ArrayList
at com.example.a7860k.reproductor.ForegroundService.onStartCommand(ForegroundService.java:82)
at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:2894)
at android.app.ActivityThread.access$2100(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1401)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Application terminated.