How to create functionality as TikTok / Musical.ly for android app?
up vote
3
down vote
favorite
Screen 1: GridView
Screen 2: Detail Page
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
add a comment |
up vote
3
down vote
favorite
Screen 1: GridView
Screen 2: Detail Page
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
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
add a comment |
up vote
3
down vote
favorite
up vote
3
down vote
favorite
Screen 1: GridView
Screen 2: Detail Page
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
Screen 1: GridView
Screen 2: Detail Page
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
android android-layout android-fragments android-intent android-viewpager
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
add a comment |
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
add a comment |
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
yes Livedata is the best solution.
– Abhay Koradiya
Nov 5 at 4:32
add a comment |
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.
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
add a comment |
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
yes Livedata is the best solution.
– Abhay Koradiya
Nov 5 at 4:32
add a comment |
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
yes Livedata is the best solution.
– Abhay Koradiya
Nov 5 at 4:32
add a comment |
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
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
answered Nov 5 at 4:26
Chanh
1128
1128
yes Livedata is the best solution.
– Abhay Koradiya
Nov 5 at 4:32
add a comment |
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
add a comment |
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.
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
add a comment |
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.
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
add a comment |
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.
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.
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
add a comment |
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
add a comment |
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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