How to pass generic list to activity

Shay Wilner 1,746 Reputation points
2024-07-11T20:56:34.23+00:00

Hello

i have a list

class Classdaysun 
    {
        public int daysun  { get; set; }
        public int monthsun { get; set; }
        public DateTime time { get; set; }        
    }
private List<Classdaysun> list1= new List<Classdaysun>();


i try to pass list1 to activity

intent.PutExtra("list1", lists1);

i get an error

can't convert list1 to android.Os.bundleThanks

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,362 questions
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. Yonglun Liu (Shanghai Wicresoft Co,.Ltd.) 43,841 Reputation points Microsoft Vendor
    2024-07-12T05:37:42.5133333+00:00

    Hello,

    Thanks for your feedback.

    Xamarin support ended on May 1, 2024 for all Xamarin SDKs including Xamarin.Forms. For more information, please check: Xamarin official support policy | .NET (microsoft.com). We will recommend you upgrade Xamarin projects to . NET MAUI, please see the Upgrade from Xamarin to .NET & .NET MAUI documentation. If you meet any questions when using MAUI, welcome to ask your questions in this Microsoft Q&A platform.

    Best Regards,

    Alec Liu.


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


  2. Bruce (SqlWork.com) 66,056 Reputation points
    2024-07-14T22:24:18.99+00:00

    you need to pass a bundle instance, or a Parcelable java class instance. .net does not support this directly. you create a java class, with Parcelable support. then import this class in .net. you then load the properties, and pass to intent.PutExtra()

    sample:

    https://damienaicheh.github.io/xamarin/xamarin.android/2018/05/26/xamarin-android-parcelable-en.html

    note: if you use this for several windows, I'd create a class that just passed a single string (you might be able to use the Bundle directly). then I'd pass a json string. (the bundle serializes, so you are not passing an object instance).

    0 comments No comments

  3. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.