android-guidelines | Project Guidelines for the Android Buffer App | Android library
kandi X-RAY | android-guidelines Summary
kandi X-RAY | android-guidelines Summary
Welcome to the Android Guidelines repo . This repository is used to house all of our project guidelines for Buffer Applications on the Android Platform.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of android-guidelines
android-guidelines Key Features
android-guidelines Examples and Code Snippets
Community Discussions
Trending Discussions on android-guidelines
QUESTION
Ok, Let's make this simple.
I've two ways to start an activity other than default startActivity
One : Using a static start
method
ANSWER
Answered 2019-Jan-24 at 11:21One is more of a command pattern, while Two is a kind of factory pattern. While both do the same (supposedly), there's one problem with One: it's actually missing the context of the caller. If you need to have a configuration on the Intent
, which might depend on the current state or the origin of the call, you'll not be able to apply it. This can be excluding it from the recent activities or disable history or clear the task or anything else.
So better go with Two to be safe and consistent. In any case you're not storing a reference to context
, therefore you won't leak it.
QUESTION
I'm writing an Android application and although I already have read about MVP and saw some examples in Android, I'm in doubt about how should I structure this part of the app.
NOTE: My app follows a structure very similar to: https://github.com/googlesamples/android-architecture/tree/todo-mvp
In this app, the Model should fetch JSON data from a web service. This data, among other stuff, contains links of images that the app should download asynchronously. And, after downloading, these images should be presented to the user.
How should I approach this?
Right now, my idea is to add the web service request logic on the Model (I'm also using the Repository pattern) and the download logic on the Presenter. Something like this (the code is just an example):
...ANSWER
Answered 2018-Apr-11 at 02:37You can have a Presenter without the need of having a view explicitly linked to that Presenter. In other words, you can have a presenter only to encapsulate some logical. In your case, you can have a presenter that only knows how to fetch and provide some images. And your view can make use of this specific presenter.
I did not get why would you have to pass the context to the model.
Right now, my idea is to add the web service request logic on the Model (I'm also using the Repository pattern) and the download logic on the Presenter. Something like this (the code is just an example):
You could do that. However, it seems more like MVVM where you put logical into Model and the Model knows how to fetch data.
In your case, you want to follow MVP, so the model only holds data (pieces of information/data). So, you can have one Presenter that knows how to download your images. And you can have some Utils
that could help you with the request part. You can have another model for that Presenter
that download images for saving your images, like a cache. And, again if you want to make some sort of cache logic, you should do on the same presenter that knows how to download an image. Or, if it becoming too big and complex, you can make a Presenter
that only knows hot to cache stuff.
Once your Presenter
only knows how to download an image, or only knows how to save an image. You can test it easy, just pass a link to your Presenter
method and check if it could handle download the image.
Note: I did not understand how could be convenient or important you pass context for your model unless it knows some sort of cache using Android preferences?
NOTE 2: I would love if I could unit test this part of the app (Mocking the DownloadManager). So, passing the Context to the Model is not an option, as it breaks the MVP (IMHO) and would be much harder to unit test it.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install android-guidelines
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page