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









up vote
3
down vote

favorite
1












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










share|improve this question























  • try loading first 50 videos and then in background load data in service.?
    – Atif AbbAsi
    Nov 5 at 4:54










  • There is library called eventbus that can help you with this problem. github.com/greenrobot/EventBus
    – Deepak S. Gavkar
    Nov 6 at 7:23














up vote
3
down vote

favorite
1












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










share|improve this question























  • try loading first 50 videos and then in background load data in service.?
    – Atif AbbAsi
    Nov 5 at 4:54










  • There is library called eventbus that can help you with this problem. github.com/greenrobot/EventBus
    – Deepak S. Gavkar
    Nov 6 at 7:23












up vote
3
down vote

favorite
1









up vote
3
down vote

favorite
1






1





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










share|improve this question















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







android android-layout android-fragments android-intent android-viewpager






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 5 at 18:21

























asked Nov 3 at 4:01









Chitrang

3,26711735




3,26711735











  • try loading first 50 videos and then in background load data in service.?
    – Atif AbbAsi
    Nov 5 at 4:54










  • There is library called eventbus that can help you with this problem. github.com/greenrobot/EventBus
    – Deepak S. Gavkar
    Nov 6 at 7:23
















  • try loading first 50 videos and then in background load data in service.?
    – Atif AbbAsi
    Nov 5 at 4:54










  • There is library called eventbus that can help you with this problem. github.com/greenrobot/EventBus
    – Deepak S. Gavkar
    Nov 6 at 7:23















try loading first 50 videos and then in background load data in service.?
– Atif AbbAsi
Nov 5 at 4:54




try loading first 50 videos and then in background load data in service.?
– Atif AbbAsi
Nov 5 at 4:54












There is library called eventbus that can help you with this problem. github.com/greenrobot/EventBus
– Deepak S. Gavkar
Nov 6 at 7:23




There is library called eventbus that can help you with this problem. github.com/greenrobot/EventBus
– Deepak S. Gavkar
Nov 6 at 7:23












2 Answers
2






active

oldest

votes

















up vote
1
down vote













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






share|improve this answer




















  • yes Livedata is the best solution.
    – Abhay Koradiya
    Nov 5 at 4:32

















up vote
0
down vote













You have several options. I'll put my opinion here.



  • Static list

  • Enum

  • Singleton class with list

  • LiveData

Most easy would be making static list at activity or application level. Just make sure you are freeing up List memory after use by making it NULL.




Another solution I found is passing data with enum, but as per
comments I'm not sure about it's performance




There would be sure some differences in each of above approaches. But that would not be measurable difference, because each approach put List in memory, use it and then free up.




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




Make static List, and make it NULL after use. will be most efficient and easy way.
You can make List NULL in onDestroy() of your Fragment.



You can use LiveData but I think it would be not a good idea to add LiveData library just for one use in app. Also you need to understand it first. So you can go with static list.



in Activity



showFragment();
ApplicationClass.list = myList;


In Fragment



onViewCreated()
...
setAdapter(ApplicationClass.list);
...


onDestroy()
ApplicationClass.list = null;



Important



It is never a good idea to pull all data at once from server. Please do pagination, which you app needs most, because there can be thousands of users online at one time.



So by that approach you will pass only few items to Fragment. then you will do pagination in Fragment.



This approach needs time to change flow a bit. But is most robust way in your case.



Edit



If you are already using pagination and still getting large data at one time, that's again an issue. Because pagination is used to escape these memory issues.



You can do 2 things as solution.
1. Ask for limited data at once, say 50-60 items per request.
2. You can map and remove unnecessary fields from your list when passing in intent.



I would prefer the first one.






share|improve this answer






















  • Thanks for the answer, but I think you didn't go through question properly as per your "Important" section in the answer. I'm already doing pagination "pagination_index". But once data is loaded in screen one with pagination. I have to pass existing data and last pagination index. But the problem is data is huge and not able to pass with intent.
    – Chitrang
    Nov 11 at 2:44










  • What your data contains that it exceed 1mb in just 100 size of list?
    – Khemraj
    Nov 11 at 3:58










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53128294%2fhow-to-create-functionality-as-tiktok-musical-ly-for-android-app%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
1
down vote













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






share|improve this answer




















  • yes Livedata is the best solution.
    – Abhay Koradiya
    Nov 5 at 4:32














up vote
1
down vote













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






share|improve this answer




















  • yes Livedata is the best solution.
    – Abhay Koradiya
    Nov 5 at 4:32












up vote
1
down vote










up vote
1
down vote









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






share|improve this answer












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







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 5 at 4:26









Chanh

1128




1128











  • yes Livedata is the best solution.
    – Abhay Koradiya
    Nov 5 at 4:32
















  • yes Livedata is the best solution.
    – Abhay Koradiya
    Nov 5 at 4:32















yes Livedata is the best solution.
– Abhay Koradiya
Nov 5 at 4:32




yes Livedata is the best solution.
– Abhay Koradiya
Nov 5 at 4:32












up vote
0
down vote













You have several options. I'll put my opinion here.



  • Static list

  • Enum

  • Singleton class with list

  • LiveData

Most easy would be making static list at activity or application level. Just make sure you are freeing up List memory after use by making it NULL.




Another solution I found is passing data with enum, but as per
comments I'm not sure about it's performance




There would be sure some differences in each of above approaches. But that would not be measurable difference, because each approach put List in memory, use it and then free up.




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




Make static List, and make it NULL after use. will be most efficient and easy way.
You can make List NULL in onDestroy() of your Fragment.



You can use LiveData but I think it would be not a good idea to add LiveData library just for one use in app. Also you need to understand it first. So you can go with static list.



in Activity



showFragment();
ApplicationClass.list = myList;


In Fragment



onViewCreated()
...
setAdapter(ApplicationClass.list);
...


onDestroy()
ApplicationClass.list = null;



Important



It is never a good idea to pull all data at once from server. Please do pagination, which you app needs most, because there can be thousands of users online at one time.



So by that approach you will pass only few items to Fragment. then you will do pagination in Fragment.



This approach needs time to change flow a bit. But is most robust way in your case.



Edit



If you are already using pagination and still getting large data at one time, that's again an issue. Because pagination is used to escape these memory issues.



You can do 2 things as solution.
1. Ask for limited data at once, say 50-60 items per request.
2. You can map and remove unnecessary fields from your list when passing in intent.



I would prefer the first one.






share|improve this answer






















  • Thanks for the answer, but I think you didn't go through question properly as per your "Important" section in the answer. I'm already doing pagination "pagination_index". But once data is loaded in screen one with pagination. I have to pass existing data and last pagination index. But the problem is data is huge and not able to pass with intent.
    – Chitrang
    Nov 11 at 2:44










  • What your data contains that it exceed 1mb in just 100 size of list?
    – Khemraj
    Nov 11 at 3:58














up vote
0
down vote













You have several options. I'll put my opinion here.



  • Static list

  • Enum

  • Singleton class with list

  • LiveData

Most easy would be making static list at activity or application level. Just make sure you are freeing up List memory after use by making it NULL.




Another solution I found is passing data with enum, but as per
comments I'm not sure about it's performance




There would be sure some differences in each of above approaches. But that would not be measurable difference, because each approach put List in memory, use it and then free up.




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




Make static List, and make it NULL after use. will be most efficient and easy way.
You can make List NULL in onDestroy() of your Fragment.



You can use LiveData but I think it would be not a good idea to add LiveData library just for one use in app. Also you need to understand it first. So you can go with static list.



in Activity



showFragment();
ApplicationClass.list = myList;


In Fragment



onViewCreated()
...
setAdapter(ApplicationClass.list);
...


onDestroy()
ApplicationClass.list = null;



Important



It is never a good idea to pull all data at once from server. Please do pagination, which you app needs most, because there can be thousands of users online at one time.



So by that approach you will pass only few items to Fragment. then you will do pagination in Fragment.



This approach needs time to change flow a bit. But is most robust way in your case.



Edit



If you are already using pagination and still getting large data at one time, that's again an issue. Because pagination is used to escape these memory issues.



You can do 2 things as solution.
1. Ask for limited data at once, say 50-60 items per request.
2. You can map and remove unnecessary fields from your list when passing in intent.



I would prefer the first one.






share|improve this answer






















  • Thanks for the answer, but I think you didn't go through question properly as per your "Important" section in the answer. I'm already doing pagination "pagination_index". But once data is loaded in screen one with pagination. I have to pass existing data and last pagination index. But the problem is data is huge and not able to pass with intent.
    – Chitrang
    Nov 11 at 2:44










  • What your data contains that it exceed 1mb in just 100 size of list?
    – Khemraj
    Nov 11 at 3:58












up vote
0
down vote










up vote
0
down vote









You have several options. I'll put my opinion here.



  • Static list

  • Enum

  • Singleton class with list

  • LiveData

Most easy would be making static list at activity or application level. Just make sure you are freeing up List memory after use by making it NULL.




Another solution I found is passing data with enum, but as per
comments I'm not sure about it's performance




There would be sure some differences in each of above approaches. But that would not be measurable difference, because each approach put List in memory, use it and then free up.




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




Make static List, and make it NULL after use. will be most efficient and easy way.
You can make List NULL in onDestroy() of your Fragment.



You can use LiveData but I think it would be not a good idea to add LiveData library just for one use in app. Also you need to understand it first. So you can go with static list.



in Activity



showFragment();
ApplicationClass.list = myList;


In Fragment



onViewCreated()
...
setAdapter(ApplicationClass.list);
...


onDestroy()
ApplicationClass.list = null;



Important



It is never a good idea to pull all data at once from server. Please do pagination, which you app needs most, because there can be thousands of users online at one time.



So by that approach you will pass only few items to Fragment. then you will do pagination in Fragment.



This approach needs time to change flow a bit. But is most robust way in your case.



Edit



If you are already using pagination and still getting large data at one time, that's again an issue. Because pagination is used to escape these memory issues.



You can do 2 things as solution.
1. Ask for limited data at once, say 50-60 items per request.
2. You can map and remove unnecessary fields from your list when passing in intent.



I would prefer the first one.






share|improve this answer














You have several options. I'll put my opinion here.



  • Static list

  • Enum

  • Singleton class with list

  • LiveData

Most easy would be making static list at activity or application level. Just make sure you are freeing up List memory after use by making it NULL.




Another solution I found is passing data with enum, but as per
comments I'm not sure about it's performance




There would be sure some differences in each of above approaches. But that would not be measurable difference, because each approach put List in memory, use it and then free up.




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




Make static List, and make it NULL after use. will be most efficient and easy way.
You can make List NULL in onDestroy() of your Fragment.



You can use LiveData but I think it would be not a good idea to add LiveData library just for one use in app. Also you need to understand it first. So you can go with static list.



in Activity



showFragment();
ApplicationClass.list = myList;


In Fragment



onViewCreated()
...
setAdapter(ApplicationClass.list);
...


onDestroy()
ApplicationClass.list = null;



Important



It is never a good idea to pull all data at once from server. Please do pagination, which you app needs most, because there can be thousands of users online at one time.



So by that approach you will pass only few items to Fragment. then you will do pagination in Fragment.



This approach needs time to change flow a bit. But is most robust way in your case.



Edit



If you are already using pagination and still getting large data at one time, that's again an issue. Because pagination is used to escape these memory issues.



You can do 2 things as solution.
1. Ask for limited data at once, say 50-60 items per request.
2. You can map and remove unnecessary fields from your list when passing in intent.



I would prefer the first one.







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 11 at 3:57

























answered Nov 10 at 12:41









Khemraj

10.4k22463




10.4k22463











  • Thanks for the answer, but I think you didn't go through question properly as per your "Important" section in the answer. I'm already doing pagination "pagination_index". But once data is loaded in screen one with pagination. I have to pass existing data and last pagination index. But the problem is data is huge and not able to pass with intent.
    – Chitrang
    Nov 11 at 2:44










  • What your data contains that it exceed 1mb in just 100 size of list?
    – Khemraj
    Nov 11 at 3:58
















  • Thanks for the answer, but I think you didn't go through question properly as per your "Important" section in the answer. I'm already doing pagination "pagination_index". But once data is loaded in screen one with pagination. I have to pass existing data and last pagination index. But the problem is data is huge and not able to pass with intent.
    – Chitrang
    Nov 11 at 2:44










  • What your data contains that it exceed 1mb in just 100 size of list?
    – Khemraj
    Nov 11 at 3:58















Thanks for the answer, but I think you didn't go through question properly as per your "Important" section in the answer. I'm already doing pagination "pagination_index". But once data is loaded in screen one with pagination. I have to pass existing data and last pagination index. But the problem is data is huge and not able to pass with intent.
– Chitrang
Nov 11 at 2:44




Thanks for the answer, but I think you didn't go through question properly as per your "Important" section in the answer. I'm already doing pagination "pagination_index". But once data is loaded in screen one with pagination. I have to pass existing data and last pagination index. But the problem is data is huge and not able to pass with intent.
– Chitrang
Nov 11 at 2:44












What your data contains that it exceed 1mb in just 100 size of list?
– Khemraj
Nov 11 at 3:58




What your data contains that it exceed 1mb in just 100 size of list?
– Khemraj
Nov 11 at 3:58

















 

draft saved


draft discarded















































 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53128294%2fhow-to-create-functionality-as-tiktok-musical-ly-for-android-app%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

Barbados

How to read a connectionString WITH PROVIDER in .NET Core?

Node.js Script on GitHub Pages or Amazon S3