Kirmani88 Kirmani88 - 7 days ago 9
Android Question

when Pressed Back Button on RecyclerView it takes to the Home Screen

I have created a Horizontal

RecyclerView
, It has
onClickListener
, When User Clicks on it, It opens
Video Player
. The Problems arises when user clicks on Back Button.

When user clicks on Back Button it takes user to the
MainActivity
and not to the original activity from where user actually launches the Video.

This is what i have done. Kindly guide me how to keep the History of previous activity when opening another activity from
recyclerView onClickListener


ListActivity

VideosRecyclerView recyclerAdapter = new VideosRecyclerView(this, videosList);
LinearLayoutManager layoutManager
= new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false);

lvRecyclerVideosList.setLayoutManager(layoutManager);
lvRecyclerVideosList.setItemAnimator(new DefaultItemAnimator());
lvRecyclerVideosList.setAdapter(recyclerAdapter);


RecyclerAdapter

public class VideosRecyclerView extends RecyclerView.Adapter<VideosRecyclerView.ViewHolder> {

public VideosRecyclerView(Context context, ArrayList<VideosService> dataList){
this.context= context;
this.dataList= dataList;
}

@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.custom_video_list, parent, false);
return new ViewHolder(v, context, dataList);
}


@Override
public void onBindViewHolder(ViewHolder holder, int position) {
VideosService item = dataList.get(position);

holder.textView.setText(item.getTitle());
videoURL= item.getVideoURL();

}


public static class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener{
public ImageView imageView;
Context context;

@Override
public void onClick(View v) {
int position= getAdapterPosition();
VideosService videosService= this.dataList.get(position);
Intent i= new Intent(context, VideoActivity.class);
i.putExtra("videoURL", videosService.getVideoURL());
context.startActivity(i);

}


Manifest

<activity
android:name=".gdvl.VideoLists
android:label="@string/app_name"
android:screenOrientation="portrait"
android:theme="@style/AppTheme.NoActionBar" />

<activity
android:name=".VideoActivity"
android:configChanges="orientation|screenSize"
android:label="@string/title_activity_video"
android:theme="@style/AppTheme" />


Edit

This is how i start VideoList

Intent i = new Intent(gdData.this, videoLists.class);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
i.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
finish();
startActivity(i);


I removed the History of the activity that starts
videoLists
, but i never removed History of
VideoLists
. This is how is start VideoPlayer

Intent i= new Intent(context, VideoActivity.class);
i.putExtra("videoURL", videosService.getVideoURL());
context.startActivity(i);

Answer

Remove i.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY); from while launching video list activity.

It will erase your history.

Comments