Code Monkey home page Code Monkey logo

Comments (10)

lloydkevin avatar lloydkevin commented on July 19, 2024 1

I'm had similar issues with Init().

Since this get's called before the view model is set as the BindingContext on the page, then you can't perform any UI activities here.

I've had to resort to saving the parameter as a member variable, then doing any of my real work in the ViewIsAppearing()

from freshmvvm.

fcogutierrez avatar fcogutierrez commented on July 19, 2024

any solution?

from freshmvvm.

rid00z avatar rid00z commented on July 19, 2024

Init method is only used for setup, not for showing messages.

It would be better to use the appearing events on the PageModel.

from freshmvvm.

fcogutierrez avatar fcogutierrez commented on July 19, 2024

Ok, when I use the ViewIsAppearing() method it it works fine.

@rid00z in my app, each time I navigate (doing push) to some pages, the PageModel needs to do some calls to server side (and will show some alert if there is some exception). Must I use ViewIsAppearing instead of Init method?

from freshmvvm.

fcogutierrez avatar fcogutierrez commented on July 19, 2024

up

from freshmvvm.

rid00z avatar rid00z commented on July 19, 2024

Yes appearing events are better but you can also set of a background task in the init method.

from freshmvvm.

fcogutierrez avatar fcogutierrez commented on July 19, 2024

Yes, the problem is where in the Init method is there any exception and, because of this exception, I want to show an alert. The navigation is broken and you cannot do any navigation.

For example, in the Init method I do something like...

    public override void Init(object initData)
    {
        base.Init(initData);

        try
        {                              
            CallToApi();
        }
        catch (Exception ex)
        {
            // Show a modal with some error message.
        }
    }

I have the feeling that I am doing something wrong...

Thanks.

from freshmvvm.

fcogutierrez avatar fcogutierrez commented on July 19, 2024

any idea guys? :-)

from freshmvvm.

blackice2999 avatar blackice2999 commented on July 19, 2024

Yeah, why you not call the api on Event? And create an activity indicator in init.

from freshmvvm.

rid00z avatar rid00z commented on July 19, 2024

Task.Factory.StartNew(() => DownloadDataFromInternet(), TaskCreationOptions.LongRunning);

from freshmvvm.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.