Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create functionality as TikTok / Musical.ly for android app?

Screen 1: GridView

enter image description here

Screen 2: Detail Page

enter image description here

Task Achieve:

1) Load all the videos in gridview from the server.

2) User clicks at any position of gridview item.

3) Open and play the particular video in detail screen.

4) On vertical scroll play next or previous videos.

Current Implementation:

GridFragment {
    ArrayList<VideoPostModel> videoPostList;
    RecyclerView gridView;

    onnItemClick() {
        Intent intent  = new Intent(this, DetailActivity.class);
        intent.putExtra("data", videoPostList);
        intent.putExtra("click_index", clickedIndex);
        intent.putExtra("pagination_index", paginationIndex);
        startActivity(intent);
    }
}

DetailActivity {
    VerticlaViewPager vertiCalViewPager;
    ArrayList<VideoPostModel> videoPostList;

    onCreate() {
        videoPostList = getIntent().getParcelableArrayListExtra("data");
        clickedIndex = getIntent().getIntExtra("clickindex", 0);
        paginationIndex = getIntent().getIntExtra("pagination_index", 0);

        VideoFragmentStatePagerAdapter viewPagerAdapter = new VideoFragmentStatePagerAdapter(videoPostList);
        vertiCalViewPager.setAdapter(viewPagerAdapter);
    }
}

Problem:

If videoPostList has more data(approx 100+ objects of VideoPostModel) while passing data from fragment to activity then app crashes, as there is a limitation of sending data with intent(https://stackoverflow.com/a/37054839/3598052).

Hacky Alternatives:

1) Static arraylist

2) Arraylist in Application class

Looking for the OPTIMAL and EFFICIENT solution to achieve above functionality.

Any suggestion, reference link or code in the direction of achieving this would be highly appreciated, and thanks in advance.

Update 1:

Another solution I found is passing data with enum, but as per comments I'm not sure about it's performance. Refrence: https://stackoverflow.com/a/14706456/3598052

like image 649
Chitrang Avatar asked Nov 08 '22 00:11

Chitrang


1 Answers

I think you can write in an activity or use Arraylist in the application as you mentioned. Or it could be a library that recently appeared in the Android Jetpack. It is similar in nature to the Arraylist in application.

ViewModel objects that make it easier to manage and store data. It lets you access data at different activities or fragments in an application. You try it and hope it will be useful to you

like image 106
Chanh Avatar answered Nov 14 '22 22:11

Chanh