我创建了一个横向RecyclerView
,它有onClickListener
,当用户点击它时,它会打开Video Player
。当用户点击后退按钮时会出现问题。
当用户点击后退按钮时,它会将用户带到MainActivity
,而不是用户实际启动视频的原始活动。
这就是我所做的。请指导我在从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);
}
清单
<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" />
修改
这是我启动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);
我删除了以videoLists
开头的活动的历史记录,但我从未删除VideoLists
的历史记录。这是如何启动VideoPlayer
Intent i= new Intent(context, VideoActivity.class);
i.putExtra("videoURL", videosService.getVideoURL());
context.startActivity(i);
答案 0 :(得分:1)
在启动视频列表活动时删除i.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
。
它会抹掉你的历史。