Cloud Storage Api: From Cloudrail
Cloud Storage Api: From Cloudrail
Cloud Storage Api: From Cloudrail
from CloudRail
1. What do you think are the reasons why Android surpassed iOS even though it
only started recently as compared to Apple’s stable technology?
For me, the reason why Android surpassed iOS is because the Android has an affordable price
compared to an iOS. The android phones have significantly better hardware and more features
than iPhones for less money. We can also do some customization in Android phones that’s why
many people like it. We can change the themes, launcher, keyboard and etc. On the other
hand, we cannot do some customization on iPhones because the Apple likes to keep things
simple and user friendly. Another reason is that, Android phones are manufactured by many
different companies and have always been on top innovation. There are new innovative
features pushed out almost every time a major company releases a new Android phone. From
in-screen fingerprint sensors to modular phones, mobile devices that run Android always seem
to have a leg up on the competition. Some of the reasons are the following: we can do some
multitasking, the majority of Android phones offer expandable memory, hardware dependency,
universal chargers, more free apps and games, better integration with Google services and etc.
In my conclusion, the Android is much more versatile, and gives us much more flexibility, and
freedom over iOS. Both are winners, as long as people use them. We can’t just say one system
is better than another because of X. They’re both tools used by different people, and in the end,
the only thing that matters is that the customers are happy.
Choose one API, discuss the features it offers, and what areas you think it needs
improvements. Explain those areas in detail.
The API that I chose is the Google Map’s API. Google Map’s API is a robust tool that we can use
to create a custom map, a searchable map, check-in functions, display live data synching with
location, plan routes, and etc. Some of the features of the Google Maps are the following: It
offers satellite imagery, aerial photography, street maps, 360° interactive panoramic views of
streets (Street View), real-time traffic conditions, and route planning for traveling by foot, car,
bicycle, air (in beta) and public transportation.
I think the improvements that Google Map’s API need is that there should be a train or bus rating.
Getting a review from other commuter will increases the trust rather than predicting how crowded it is.
They should also partner with Zomato or similar platforms because Google Maps gives restaurants
options around a certain area but these options do not have restaurant menu, pics and proper customer
ratings. And they should also partner with brands to provide relevant location-based discount/coupon
information. Overall, the Google Maps API is really powerful and useful to many of us.
Thanks for raising this question, I have few request, yet to write to Google, good it was
raised here, hope Google Map team looks at this.
1. When you query for driving directions to a huge building complex, the
entrance is not accurate, it simply shows entrance of that building to the
nearest road, which isn’t always correct, so Google needs to map entrance
of buildings, areas.
2. This one is bit complex, I hope it gets through, when we query for driving
directions say for a location which 2 hours away, Google maps calculates
time based on current traffic density, which isn’t correct, reason being,
when I say I’ll be reaching my destination after 2 hours, so I wish google
predicts traffic density for that time based on previous data and displays
the traffic density.
3. Lat/Lon coordinates to be displayed in user friendly format, its currently
available, but its a workaround to get this info.
These are few I had in mind which I could recollect, will update as and when I come up with
new features.
I think the improvements that Google Map’s API need is that there should be a train or bus rating.
Getting a review from other commuter will increases the trust rather than predicting how crowded it is.
They should also partner with Zomato or similar platforms because Google Maps gives restaurants
options around a certain area but these options do not have restaurant menu, pics and proper customer
ratings. And they should also partner with brands to provide relevant location-based discount/coupon
information. Overall, the Google Maps API is really powerful and useful to many of us.
) Partner with Zomato or similar platforms. Currently, Google Maps gives restaurants
options around a certain area but these options do not have restaurant menu, pics & proper
customer ratings.
2) Integrate Bloggers with Google Maps to provide relevant aggregated topics on places-
to-see and other travelers’ experiences.
1. Among the Android APIs, which do you think is the best and the worst? Explain
your answer.
For me, the best Android API would be the Cloud Storage API from CloudRail
because it allows us to manage, maintain and backup all our data whether
images, videos, databases, files, contacts, confidential documents and other
important data with complete security and no data loss threat. It allows us to
store files online, so that data can be access from anywhere and anytime.
The cloud storage API is an application program interface that connects a locally-
based application to a cloud-based storage system, so that a user can send data
to it and access and work with data stored in it. The benefits of Cloud Storage
include: a new level of security, it saves money, data transfer, no need for server
maintenance, broadened accessibility and it saves physical space. Some of the
clous providers are the Microsoft (OneDrive), Dropbox and Google drive.
The worst Android API would be the Camera2 API because its library is poorly
documented and there are so many callbacks that the developers have to
manage just to take one picture. Many of the devices (lollipop, marshmallow) don't
have support for camera 2 API so we need to use legacy API for those devices. And
it is very lag on others phones. The Camera2 API gives developers access to
certain features of the phone’s camera via the software. It was first introduced
by Google in Android 5.0 Lollipop, with the purpose to extend the camera quality
by controlling aspects like the shutter speed (ISO), auto-focus, RAW Capture, etc.
One reason why Camera2 confuses developers is that there are so many
callbacks that we have to manage just to take one picture.
Camera 2 API(application program interface) is something which allows an app to access the
phones hardware, camera in this case.
The interface let's the desired application use the hardware at its full capacity. It is used in
third party camera applications and cannot be enabled through another app or a menu in
the settings.
Some phone manufacturers give this API enabled out-of -the-box, i.e. you do not need to
enable it and can use another camera app like Google camera with full efficiency as your
stock camera(the one which is provided by the phone's manufacturer).
To enable it first you need to check whether it can be done or not, if it is possible, a simple
adb command can toggle it on or off. The commands are different for different phones, so
you will need to search a bit for this.
Remember that enabling camera 2 API gives the app full control of the hardware while in
use, so trusted apps should be used. Google camera ports are very good for taking excellent
photos and pushing your phone's camera to its limits!
E. Android Runtime – ART Android Runtime environment is an important part of
Android rather than an internal part and it contains components like core
libraries and the Dalvik virtual machine. The Android run time is the engine that
powers our applications along with the libraries and it forms the basis for the
application framework.
Dalvik Virtual Machine (DVM) is a register-based virtual machine like Java Virtual
Machine (JVM). It is specially designed and optimized for android to ensure that
a device can run multiple instances efficiently. It relies on the Linux kernel for
threading and low-level memory management.
Dalvik Virtual Machine (DVM) which is responsible for running a mobile application.
Dalvik ART
Uses Just-In-Time (JIT) approach, which results Uses Ahead-Of-Time (AOT) approach, which
in lower storage space consumption but longer compiles apps when they’re installed, resulting
app load times in faster load times and lower processor usage
Cache builds up over time, so boot times are Cache is built at first boot, hence rebooting
faster device takes significantly longer
Works better for lower internal storage devices Consumes much more internal storage space
as space occupied is lesser since it stores compiled apps in addition to the
APKs
Is stable and time tested – VM of choice for app Is highly experimental and new – not a lot of
developers support from app developers yet
The difference between Dalvik and ART is that the Dalvik works better for lower internal storage devices
while the ART consumes much more internal storage space. Another difference is that Dalvik is stable
and time tested while the ART is highly experimental and new.
ART is the new runtime that executes application instructions. In other words, when you run
an app, it goes through a runtime. Previously, Android's runtime was called Dalvik and, while
it did okay, it was still a bottleneck as it only ran code at the moment it needed to (what's
called a "Just-In-Time" or JIT compiler). ART, on the other hand, uses an Ahead-of-Time
compiler (AOT) to process application instructions before they're needed so things run more
smoothly for the user. A lot of people have turned it on in 4.4 and reported great increases
in performance and Battery life. The folks at Android Police did some tests to see how
accurate these claims were.
Android Police found that there's still plenty of optimization left to be done. At the moment,
ART can squeeze out very slightly better battery life and performance than Dalvik can, but
you probably won't see massive gains—and those who claim they do are likely seeing a bit
of placebo effect. Furthermore, while lots of apps have been optimized to work with ART,
some don't at all. Many applications crash and are not supported over ART.
Dalvik was the Android runtime. If your app runs well on ART, then it should work on Dalvik as well, but
the reverse may not be true.
1. What is the relationship of Android Runtime (ART) to Dalvik Virtual Machine?
The relationship of Android Runtime (ART) to Dalvik Virtual Machine is that the Dalvik was the
Android runtime. If our app runs well on ART, then it should work on Dalvik as well, but the
reverse may not be true. ART is the new runtime that executes application instructions. In other
words, when we run an app, it goes through a runtime. Previously, Android's runtime was
called Dalvik and, while it did okay, it was still a bottleneck as it only ran code at the moment it
needed to (what's called a "Just-In-Time" or JIT compiler). ART, on the other hand, uses an
Ahead-of-Time compiler (AOT) to process application instructions before they're needed so
things run more smoothly for the user. The Android runtime provides an implementation of the
standard java library and some mechanism for taking the dex bytecode that apps are deployed
to the device in and converting it to the machine code that actually runs on the hardware. On
the other side, the Dalvik VM is older than the Android runtime. It uses a JIT compiler to convert
dex to machine code as it is run. This might seem a suboptimal time to be compiling bytecode to
machine code however a just-in-time compiler has the advantage of using information of specific
runtime characteristics to provide further optimizations for subsequent uses. The difference
between Dalvik and ART is that the Dalvik works better for lower internal storage devices while
the ART consumes much more internal storage space. Another difference is that Dalvik is stable
and time tested while the ART is highly experimental and new.
1. Among the five components of Android Architecture which is the most
important for you? Why?
The most important Android Architecture from me would be the Linux Kernel because it
provides features such as security, process management, memory management, device
management and multitasking. The Linux Kernel is the bottom-most, core part and important
layer of the Android Architecture. "Linux is open source" that means, one can make
enhancements upon the Linux kernel structure (maintaining the GNU license agreement). Being
the first layer of software, Linux kernel is the foundation of the Android platform. It allows
Android to take advantage of major OS functions and security features of a well-known kernel.
It also helps device manufacturers to develop hardware drivers more easily in a well-known
environment. The Linux Kernel will provide an abstraction layer between the device hardware
and the remainder of the stack. The kernel, if implemented properly, is invisible to the user,
working in its own little world known as kernel space, where it allocates memory and keeps
track of where everything is stored. What we see as user are web browsers and files and these
are known as the user space. These applications interact with the kernel through a system call
interface (SCI). The Linux Kernel works as a bridge between the applications and data
processing at the hardware level with the benefit of its inter-process communication and
system calls.
1. The easy way - launch the camera with an intent, designating a file path, and handle the
onActivityResult.
2. The hard way - use the Camera API to embed the camera preview within your app, adding your
own custom controls.
1. Explain how the camera of your smartphone captures an image and save
it to your device. What do you think are the possible libraries used in the
process?
There are camera implementation depends on the level of customization required, the easy
way is to launch the camera with an intent, designating a file path, and handle the
onActivityResult. The hard way is to use the Camera API to embed the camera preview within
our app, adding our own controls. In oreder to capture an image from camera, first in manifest
file we need to declare that our app uses camera by using uses-feature element. This is to let
external entity like play store know that the app uses camera hardware. Notice that required
attribute is set to false to disable the feature if device doesn’t have camera so that the app can
be installed on devices which don’t have camera to let users use other features of app.
<uses-feature android:name="android.hardware.camera"
android:required="false" />
Then send intent from our activity to start activity in camera application which allows user to
capture pictures. We will start camera activity using startActivityForResult method so that
calling app can know once photo capture is complete.
In order to access the public directory, we need to request for READ_EXTERNAL_STORAGE and
WRITE_EXTERNAL_STORAGE permissions.
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
Using FileProvider, get file URI, add it to intent as extra and then start activity. Then we need to
define the FileProvider in manifest file. Define list of file paths for FileProvider in xml file and
save it in res/xml folder. Since we want to save only in public picture directory, we’ll just add
path of it to xml. In our activity, provide implementation for onActivityResult method so that
the activity will know that the photo is captured and saved and do further actions such as
displaying the captured image in ImageView. Once photo is captured, camera app will be closed
and focus will be returned to the calling activity. But on some devices, camera app sends the
result to calling activity without finishing itself meaning the camera app will continue to be
active after sending the result to calling activity. In this case, user will have to close the app to
get back to your app.
I think the library would be used in this process is the Glide Image library for the output of the
image file over the ImageView and CameraView to help Android developers easily integrate
Camera features.
1. What do you think is the best layout that you can use in creating an Android
application? Explain why and make a comparison from other layouts available
in Android Studio.
For me, I think the best layout would be the LinearLayout because this is the layout that I am
most familiar with. The LinearLayout is the most basic layout in android studio, that aligns all the
children sequentially either in a horizontal manner or a vertical manner by specifying
the android:orientation attribute. If one applies android:orientation=”vertical” then elements
will be arranged one after another in a vertical manner and If we
apply android:orientation=”horizontal” then elements will be arranged one after another in a
horizontal manner.
ConstraintLayout , which is now the default layout in Android Studio, gives you many ways to
place objects. You can constrain them to their container, to each other or to guidelines. This
allows you to create large, complex, dynamic and responsive views in a flat hierarchy. It even
supports animations!
For me, I think the best layout would be the Constraint Layout because this is the latest and best
layout for all android phones. It's similar to Relative Layout and all views are laid out according
to relationships between sibling views and the parent layout, but it's more flexible than Relative
Layout and easier to use with Android Studio's Layout Editor. It allows us to place constraints on
view which makes it flexible to adjust on all screen size without losing attractiveness of
view. The Constraint Layout gives us many ways to place objects. We can constrain them to
their container, to each other or to guidelines. This allows us to create large, complex, dynamic
and responsive views in a flat hierarchy. It also supports animations. For example, child
elements can be positioned to top of parent and to the right of parent, also you can position
elements with constraint to other child elements.
There are also other layouts in Android like Relative Layout, Linear Layout, Table Layout,
Absolute Layout, and Frame Layout. The Relative Layout is a view group that displays child views
in relative positions. The Linear Layout is a view group that aligns all children in a single
direction, vertically or horizontally. The Table Layout is a view group that group views into rows
and columns. The absolute layout enables us to specify that exact location of its children. And
Frame Layout which is a placeholder on screen that we can use to display a single view. Besides
there is NO single best Layout. Most of the time a combination of different layouts is used to
create a design.
1. What are the commands that you can use in creating and loading an Activity
within your Android application?
Another command to load or start a new activity is by using an intent. An Intent is a simple
message object that is used to communicate between android components such as activities,
content providers, broadcast receivers and services. Intents are also used to transfer data
between activities. Intents are used generally for starting a new activity using startActivity().
The code below is an example of starting or loading a new activity using an intent:
@Override
protected void onCreate(Bundle savedInstanceState) {
Intent intent = getIntent();
String value = intent.getStringExtra("key"); //if it's a string you stored.
}
Another commands are by using the onClick attribute of the button. Assigning an
onClickListener() via anonymous class and Activity wide interface method using the switch
statement.
onResume
On the other hand, the system will invoke onResume() call back method when an activity
entered into resumed state. In this state, the activity start interacting with the user and they
can see the functionality and designing part of the application on the single screen. Mostly the
core functionality of an app is implemented in onResume() method. The app will stay in
this resumed state until another activity happens to take focus away from the app like getting a
phone call or screen turned off, etc. In case if any interruption events happen in Resumed state,
the activity will enter into Paused state and the system will invoke onPause() method.
After an activity returned from Paused state to Resumed state, the system again will
call onResume() method due to this we need to implement onResume() method to initialize the
components that we release during onPause() method
An example scenario is when a user is in Activity 1 traverses to Activity 2. The Activity 1 is not
visible at all then the user clicks the back button from Activity 1, the OnResume()method of
Activity 1 gets called again. So most of the time the user is dealing with the OnResume()
method.
onRestart
The onRestart() method will invoke by the system when an activity restarting itself after
stopping it. The onRestart() method will restore the state of activity from the time it is stopped.
This callback method in android activity is always followed by onStart() method.
An example scenario is when the user presses the home button and comes to launcher. In this
case, activity is not destroyed and pause/stop events are fired. When the user opens the app
again, onRestart() for that activity is called before onCreate().
OnPause vs onStop
If you can still see any part of it (Activity coming to foreground either doesn't occupy the
whole screen, or it is somewhat transparent), onPause () will be called. If you cannot
see any part of it, onStop () will be called. A dialog**, for example, may not cover the
entire previous Activity, and this would be a time for onPause () to be called.
If you can still see any part of it (Activity coming to foreground either doesn’t occupy the
whole screen, or it is somewhat transparent), onPause() will be called. If you cannot see
any part of it, onStop() will be called. A dialog**, for example, may not cover the entire
previous Activity, and this would be a time for onPause() to be called.
After moving the unassignment process from onStop() to onPause() everything works
as aspected because onPause() is called before the Activity is being supsended. The
Activity state diagram shows the invokation order cheers, Chris
The onPause() is called when an activity is about to lose focus. onStop() is called
when the activity is has already lost the focus and it is no longer in the screen. But
onPause() is called when the activity is still in the screen, once the method
execution is completed then the activity loses focus. So, onPause() is logically
before onStop().
onPause()
When an activity goes out of focus, onPause() method is invoked by android system. But
onPause() is called when the activity is still in the screen, once the method execution is
completed then the activity loses focus. So, onPause() is logically before onStop(). Pause is the
preparation stage before running another activity. This is the place where the existing state of
the activity should be persisted. From onPause() it is possible to call onResume() but it is not
possible once onStop() is called. Once onStop() is called then onRestart() can be called.
An example scenario of onStop() method is when we are using Facebook App then we decide to
click the home button and we go to the launcher. This is the time that the Facebook App is at an
onStop() state because the app is not currently visible on the user screen.
onStop()
When your activity is no longer visible to the user or it goes in background, it has entered
the Stopped state, and the system invokes the onStop() callback. This may occur, for example,
when a newly launched activity covers the entire screen. The system may also
call onStop() when the activity has finished running, and is about to be terminated. In
the onStop() method, the app should release or adjust resources that are not needed while the
app is not visible to the user. For example, the app might pause animations or switch from fine-
grained to coarse-grained location updates. Using onStop() instead of onPause() ensures that
UI-related work continues, even when the user is viewing the activity in multi-window mode.
An example scenario is of onPause() method when we have Facebook running on your phone
currently. If you receive a notification from WhatsApp (in the pop-up dialog box), your
Facebook activity will be paused. If you close the WhatsApp pop-up during this time, the
Facebook Activity will get Resumed. On the other hand, if you open WhatsApp from the pop-up
message, your Facebook Activity will be stopped.
Whenever some new activity occurs and occupies some partial space of the Screen. So
your previously running activity is still visible to some extent. In this Case, the previously
running activity is not pushed to Back Stack. So, here only onPause() method is called.
On other hands, if some new Activity occurs and occupies the full screen so that your
previously running activity is disappeared. In this Case, your previously running activity is
moved to Back Stack. Here, onPause() + onStop() are called.
To Summaries-
onPause()- Screen is partially covered by other new activity. The Activity is not moved to
Back Stack.
onPause() + onStop()- Screen is fully covered by other new activity. The Activity is moved to
Back Stack.
If we are designing a complex user interface, it is difficult to be divided into several children
linear layout due to a compound relationship between different UI components. We need more
time and effort to implement a UI in which all children views are aligned in different directions.
Linear layout has only basic functionality like orientation, and sometimes it becomes hard to
create complex UI. Nesting of many linear layout could result to a slow rendering of the view and
it can cost you to much memory. If cases like this take too long, they can prevent a frame from
rendering within the allowed 16ms, so that frames are dropped, and animation becomes janky.
1. In what scenario is it best to use RelativeLayout? Give at least two kinds of
Android applications that can utilize this kind of layout.
It is best to use the relative layout when we are designing a complicated layout that will require
us to nest a bunch of layouts together. A Relative Layout is a very powerful utility for designing a
user interface because it can eliminate nested view groups and keep the layout hierarchy flat,
which improves performance. Instead of using a nested Linear Layout groups, it is much better
to replace them with a single Relative Layout. The Relative Layout enables us to specify how
child views are positioned relative to each other. The image below is an example of a Relative
Layout. The position of each view in the example are specified as relative to sibling elements or
relative to the parent.
An example of application that utilizes a Relative Layout would be a Calculator App because
each button has a relation to each other. Using Relative Layout in a Calculator would make the
positioning of buttons easier.
Another example that utilizes a Relative Layout would be a a log in screen of an app or a Email
App. The text view and edit text of the log in and Email app can be specified as relative to
sibling or parent elements.
1. Provide one example of implementation of LongClick(). When do you think you
can properly use this in your application?
The code below is an example implementation of onLongClickListener(). When we long click the
button, the TextView changes from “Hello World” to “You long click the Button”. I also tried the
onClickListener() to differentiate the two event listeners.
I think I can properly use the onLongClickListener() in a ListView so that when I long click the
one item, I can also select the other items in a ListView. Also, I can apply it on selecting multiple
images in a Gallery. And sometimes I long click the files in my file manager when I’m deleting
multiple files. I can implement the onLongClickListener() when I develop a mobile game that
needs a long click.
1. Identify at least two (2) issues about Intent in Android Application, describe
each concern, and discuss how to resolve these.
Issue 1:
One of the issues about intent is when we invoke an intent and there is no app available on the
device that can handle the intent, the app crashes. Not every user has the same set of
applications installed so we need to verify that there is an app to receive the intent.
Solution:
If isIntentSafe is true, then at least one app will respond to the intent. If it is false, then there
aren't any apps to handle the intent.
We should perform this check when our activity first starts in case we need to disable the feature
that uses the intent before the user attempts to use it. If we know of a specific app that can handle
the intent, we can also provide a link for the user to download the app.
Although the Android platform guarantees that certain intents will resolve to one of the
built-in apps (such as the Phone, Email, or Calendar app), you should always include a
verification step before invoking an intent.
Caution: If you invoke an intent and there is no app available on the device that can handle the
intent, your app will crash.
KOTLINJAVA
PackageManager packageManager = getPackageManager();
List<ResolveInfo> activities =
packageManager.queryIntentActivities(intent,
PackageManager.MATCH_DEFAULT_ONLY);
boolean isIntentSafe = activities.size() > 0;
If isIntentSafe is true, then at least one app will respond to the intent. If it is false,
then there aren't any apps to handle the intent.
Note: You should perform this check when your activity first starts in case you need to disable the
feature that uses the intent before the user attempts to use it. If you know of a specific app that can
handle the intent, you can also provide a link for the user to download the app (see how to link to
your product on Google Play).
As discussed before, you can put arbitrary extras into your intent, but you
should be careful what and how much you put in there. As mentioned earlier,
the system will throw a TransactionTooLargeException if you try to put too much
data into an intent. To work around this, there are plenty of tools you can use.
If you are just trying to pass large data from one Activity to another in your
application, you could, for example, store the data in your application’s file
directory and put just the path in the intent. On the other hand, if you are trying
to pass large amounts of data to an external application, you should consider
using a ContentProvider, which will allow you to use the URIs it provides and
pass them to any application you want.
Issue 2:
Solution:
If we are just trying to pass large data from one Activity to another in our application, we could,
for example, store the data in our application’s file directory and put just the path in the intent.
On the other hand, if we are trying to pass large amounts of data to an external application, we
should consider using a ContentProvider, which will allow us to use the URIs it provides and
pass them to any application we want.
Caution: Using an intent filter isn't a secure way to prevent other apps from starting your
components. Although intent filters restrict a component to respond to only certain kinds of implicit
intents, another app can potentially start your app component by using an explicit intent if the
developer determines your component names. If it's important that only your own app is able to start
one of your components, do not declare intent filters in your manifest. Instead, set
the exported attribute to "false" for that component.
Similarly, to avoid inadvertently running a different app's Service, always use an explicit intent to
start your own service.
Note: For all activities, you must declare your intent filters in the manifest file. However, filters for
broadcast receivers can be registered dynamically by calling registerReceiver(). You can then
unregister the receiver with unregisterReceiver(). Doing so allows your app to listen for specific
broadcasts during only a specified period of time while your app is running.
Issue 3
Using an intent filter isn't a secure way to prevent other apps from starting the components.
Although intent filters restrict a component to respond to only certain kinds of implicit intents,
another app can potentially start your app component by using an explicit intent if the
developer determines your component names.
Solution:
If it's important that only your own app is able to start one of your components, do not declare
intent filters in your manifest. Instead, set the exported attribute to "false" for that component.
Similarly, to avoid inadvertently running a different app's Service, always use an explicit intent
to start your own service.
For all activities, you must declare your intent filters in the manifest file. However, filters for
broadcast receivers can be registered dynamically by calling registerReceiver(). You can then
unregister the receiver with unregisterReceiver(). Doing so allows your app to listen for specific
broadcasts during only a specified period of time while your app is running.
1. When do you think it is necessary to use Explicit and Implicit Intent in an
Android Application?
It is necessary to use the Explicit Intent when we are starting activities within
our own application. At that point we know exactly which activity we want to start, so
there is no reason to go through the extra work of setting up the implicit intents. Explicit
Intents are used to call a specific component. When we know which component we want to
launch and we do not want to give the user free control over which component to use.
The image below shows an example of explicit intent where in the application has 2
activities, the First Activity and Second Activity. If we want to launch Second Activity from
First Activity, we need to click the button. In this case we define an explicit intent targeting
Second Activity and then use it to directly call it.
//We need to check to see if there is an application installed that can handle this
intent
if (getPackageManager().resolveActivity(intent, 0) != null){
startActivity(intent);
}else{
//Handle error
}
It is necessary to use the Implicit Intents when we do not directly specify the Android
components which should be called, it only specifies action to be performed. The Implicit
Intents are used when we have an idea of what we want to do, but we do not know which
component should be launched. Or if we want to give the user an option to choose between
a list of components to use. If these Intents are sent to the Android system it searches for all
components which are registered for the specific action and the data type. If only one
component is found, Android starts the component directly. For example, we have an
application that uses the camera to take photos. One of the features of our application is
that we give the users the possibility to send the photos they have taken. We do not know
what kind of application the users have that can send photos, and we also want to give the
user an option to choose which external application to use if they have more than one. In
this case we would not use an explicit intent. Instead, we should use an implicit intent that
has its action set to ACTION_SEND and its data extra set to the URI of the photo. A Uri can
be used with the implicit intent to specify the data type. For example:
The code above is an another example implementation of Implicit Intent where in it will
cause web browser to open a webpage. Android system searches for all components which
are registered for the specific action and the data type. If many components are found then
the user can select which component to use.
1. What types of values can we store and share using Intent? How do we save these
values from the source? How do we pass it to its destination activity or
application?
The types of values that we can store and share using intent are images, text, videos, links, and
etc. We can share the local content of our app to the other apps and vice versa. Intents allow us
to interact with components from the same applications as well as with components contributed
by other applications. For example, an activity can start an external activity for taking a picture,
we can also access the contacts, file storage, play a video or music, load a web URL and etc.
There are so many things that we can store and share using intent.
Android supports explicit and implicit intents. An application can define the target component
directly in the intent (explicit intent) or ask the Android system to evaluate registered
components based on the intent data (implicit intents). Explicit intents are typically used within
an application as the classes in an application are controlled by the application developer. We
can send data while calling one activity from another activity using intent. All we have to do is
add the data to Intent object using putExtra() method. The data is passed in key value pair. The
value can be of types like int, float, long, string, etc. The example below is sending data and it is
just sending one value, in the same way we can attach more values by using putExtra() method.
Sending Data
Retrieving Data
If the data sent is of type string then it can be fetched in following way.
Intent intent = getIntent();
String str = intent.getStringExtra(Key);
There are several other methods like getIntExtra(), getFloatExtra(), etc to fetch other types of
data.
On the other hand, the Implicit intents specify the action which should be performed and
optionally data which provides content for the action. If an implicit intent is sent to the Android
system, it searches for all components which are registered for the specific action and the fitting
data type. There are many other actions available
like ACTION_SEND,ACTION_DIAL,ACTION_PICK,ACTION_CALL etc. For example, the following
tells the Android system to view a webpage. All installed web browsers should be registered to
the corresponding intent data via an intent filter.
The following are some the examples of sending and receiving data using Intent:
SenderActivity
SenderActivity
SenderActivity
2. Aside from the discussed common UI controls, what other controls do you
think should a new developer need to familiarize? Why?
I think the other controls that a new developer should know are the SeekBar, VideoView,
Switch, ZoomControls, SearchView and RatingBar. The Seekbar is an extended Progress bar. A
seekbar comes with a pointer that is draggable throughout the bar either in left or right. This
helps the user to choose a particular range of values. The VideoView is used to display a video
file. The switch is a two-state UI element that holds either ON or OFF state. By default, a switch
is in the OFF state. A user can change its state many times. The Zoom Controls class display
simple set of controls that is used for zooming and provides callback to register for
events. Zoom Controls has two buttons ZoomIn and ZoomOut which are used to control the
zooming functionality. The SearchView widget provide search user interface where users can
enter a search query and then submit a request to search provider. And the RatingBar is an
extended version of a seekbar. It is used to give the rating by touching it. In the rating bar, a
user can rate at a scale of 5 with a difference of 0.5.
The other controls in android are the control external devices. The Quick Access Device Controls
feature allows the user to quickly view and control external devices such as lights, thermostats,
and cameras from the Android power menu. The developer needs to familiarize themselves in
this control so that they can help the user to access the control external devices in easier way
and the user don’t need to those devices because they can see it immediately.
Those are some of the controls that a developer needs to know so that they can provide a good
user experience to the user and they can design a UI in a more interactive way.
1. Give two important events that can implement in a Spinner. How can we register
these events?
The Spinners provide a quick way to select one value from a set. In the default state, a spinner
shows its currently selected value. Touching the spinner displays a dropdown menu with all
other available values, from which the user can select a new one.
The first event that can implement in a Spinner is the setOnItemSelectListener or
onItemSelected. The onItemSelected is triggered when the user selects an item from the drop-
down. The spinner object receives an on-item-selected event. The second event is the
onNothingSelected. The onNothingSelected is triggered when the Spinner has no items or the
user deselects all items. The selection can disappear for instance when touch is activated or
when the adapter becomes empty.
To define the selection event handler for a spinner, we need to implement the
AdapterView.OnItemSelectedListener interface and the corresponding onItemSelected()
callback method..Below is the example implementation: