In the last Blog Post you learnt how to create device specific resources like Layout, Menu, Images etc.
On a phone the Employee App will display list of Employees initially and on click of an employee the DetailActivity will be called. Whereas on a Tablet the List and the Detail is shown next to each other.
Question is how to achieve this?
If you take a look at the Layout XML file you will find that for a Tablet you have a FrameLayout.
So you can check in the Activity class that if this attribute exists then its a tablet. If not then call the DetailActivity.
Source Code – Github
Follow the video to understand this better.
When you use an App on your Android Device I am sure you press the back button pretty often. Which in turn takes you to the previous Screen.
This happens because of the Back Stack which maintains a history of places you have visited.
Each visit is a transaction. So the back stack essentially keeps an eye on all the transactions. Using the back stack effectively can lead to to a good user experience.
A transaction can be moving from one Activity to another or from one Fragment to another. So if the user wants to go back to the previous Activity or Fragment
the Back Button will enable that action.
How this concept applies to our App we will discover in the next Article.
Read the Android Documentation to explore this further.
In the last Tutorial you learnt about Fragments and why to use them.
Using a Fragment with an Activity is pretty simple to start with. You need to add the fragment attribute to the activity layout file. Follow the short video to know how to do this.
Refer to the code here
This Article assumes that You are familiar with the Activity Lifecycle. If not please read my last Post.
There are two more methods which come into picture when an Activity becomes partially visible.
These two Lifecycle methods are onPause and onResume. Please refer to the image and to the Video to understand this better.
Android Activity follows a Lifecycle from its time of creation till it gets destroyed. In this Article you will Learn about the Lifecycle.
As you can see in the attached diagram an Activity starts when its Launched. That’s the time its Constructor is run and object is created.
This is followed by the onCreate method which is responsible for Screen setup.
Continue reading “Android Basics – What is the Activity Lifecycle”
It is possible to call an Activity in another App from your App by using an Implicit Intent.
In the last Article you saw how to use an Explicit intent to call an Activity in
the same App.
A Scenario can be if you want to send a Text Message when the user clicks on a Button in your App.
To achieve this you need to know a few basic concepts:
In an Explicit Intent you need to specify the Action – like Email, Message, Call – basically what kind of Intents you want to use.
Continue reading “Android Basics – Call an Activity in another App using Implicit Intent”
In Android App you can have multiple Activities. Each Activity performs a certain task. At times it needs to call another Activity.
To do this Intent is used. Which means an intent to do something.
To call a new MessageActivity from the MainActivity – on click of a Button add the following two lines in your MainActivity
Intent intent=new Intent(this, MessageActivity.class);
That’s it !