Hi i have listview with custom adapter on bindviewholder i have:
@Override
public void onBindViewHolder(final AdapterRecyclerViewEventiComposti.ViewHolder holder, final int position)
{
String tmp=listaEventiComposti.get(position);
holder.title.setText(tmp);
holder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
context.startService(new Intent(context, GestioneEvento.class));
}
});
}
When i click on item on listview i execute GestioneEvento that extends Service into method onStartCommand i have:
@Override
public int onStartCommand(Intent intent, int flags, final int startId) {
Runnable r = new Runnable() {
public void run() {
//execute my operations
}
};
Thread t = new Thread(r);
t.start();
return Service.START_STICKY;
}
I want to that when i click on item of listview i create a new thread and every life cycle of thread is separated. For example: ListView Item1 Item2 Item3
I click on Item1 and start new thread, immediately after i click Item2 and start new thread, then i click again Item1 and i stop only thread of Item1 while Item2 continues to work in the background. So as I did above is correct? Now if i want only stop thread of Item1 how should I do?