Create/Add Raw Folder In Android Studio

Raw folder in Android is used to keep mp3 or ogg audio files and also video files. The raw folder is created inside \app\src\main\res\raw. So we will simply create it inside res folder. Here is the simple way to create raw folder in android studio:


How To Create/Add Raw Folder In Android Studio

Step 1: Open App folder and select res folder

Step 2: Right click on res folder, select New> Android resource directory, then studio will open a dialog box and it will ask you to enter the name.

1

Step 3: Write “raw” and selectResource type” then click OK. Open res folder and you will find your raw folder under it.

2

 

Next Step: How To Add & Play Audio File In Raw Folder

JAVA For Android Developer– Tutorial, Examples, And Programs

Advertisements

JAVA For Android Developer– Tutorial, Examples, And Programs

Android App are mostly developed in JAVA language using Android SDK (Software Development Kit). Other languages like C, C++, Kotlin etc. can also be used for developing Android App, but JAVA is most preferred and mostly used programming language for Android App Development. So if you are a beginner in Android then JAVA language and complete knowleadge of OOPS concepts is the first thing you need to learn before beginning Android Development.


Introduction To JAVA

Java is a general-purpose computer-programming language that is concurrent, class-based, object-oriented, and specifically designed to have as few implementation dependencies as possible. It is intended to let application developers “write once, run anywhere” (WORA), meaning that compiled Java code can run on all platforms that support Java without the need for recompilation.JAVA is a programming language which is also used in Android App Development. It’s syntax is influenced by C++. The primary goals of JAVA is to be simple, object-oriented, robust, secure and high level.

JAVA application runs on JVM (JAVA Virtual Machine) but Android has it’s own virtual machine called Dalvik Virtual Machine (DVM) optimized for mobile devices.


Prerequisites For JAVA:

IntelliJ IDEA:

Being a JAVA programmer you will need some tools or software to code and run it. Lots of tools are available over the web but we recommend you to use IntelliJ IDEA for learning JAVA since Android Studio build based on IntelliJ IDEA. So getting habitual with IntelliJ IDEA and its shortcuts will be bonus in your Android journey. Other then IntelliJ IDEA you can also prefer Eclipse or netbeans for learning JAVA.

Other Tools: Eclipse and Netbeans


Tutorial On JAVA Topics For Android Developer:

Below are the tutorials on JAVA:

Introduction to Java

 
Topics (Follow the link to read tutorial) Description
Variables

 

Java Buzzwors

Learn about variables and how they are created for storing information in memory

The key considerations were summed up by the Java team in the following list of buzzwords:

Data Types Learn about Data Types (i.e. byte, int, char etc) which is basically a type of information we want to store in variable.
String String is nothing but a character array for example “ruatech” is a string of 7 characters as shown.
Operators|Set 1|Set 2|Set 3|Set 4 In computer programming Operator is a symbol that tells the compiler to perform specific action which can be mathematical or logical.
Keywords Keywords in JAVA are predefined list of keywords which has a specific meaning and cannot be used in the Java programming language as an identifier, such as the name of a variable, method, class, function, or label.
Class And Objects The concept of class comes into role when we see certain type of objects or things around us and the common idea or a blueprint behind this type of objects is called Class. Object is an instance of class.
Method A method is a self contained block of code that performs a specific task.
If Then Else|set1

If Then Else|set2

If then allow us to control the flow of program based on conditions, whether to execute a code or not.
For Loop In JAVA For statement is the most commonly used lopping statement which iterate over a range of numbers.
While Do While

 

 

 

switch statement

The While is a type of loop which evaluate the condition first. If condition evaluate to true the code inside the block{} will be executed and if it evaluate to false it will jump outside the while loop.

 

A switch statement tests a variable for equality against a list of values. Each value is called a case, and the variable being switched on is checked for each case.

Arrays Array can be defined as a contiguous memory locations used to store the homogeneous data types. In simple words, it is a variable that can store multiple values of single data type.
Inheritance It is a mechanism that allows the class to use the states and behavior of another class.
Abstraction It is a process of hiding internal working and showing only necessary details.
Method Overriding Method Overriding means to re-write the previous described method again of Parent Class in Sub class with different functionality.
Method Overloading It allows multiple methods to have same name if the parameter list inside parenthesis are different.
Interface It is able to achieve 100% abstraction as it only contains those methods which has no implementation (i.e. methods without body).
Encapsulation Wrapping up of data member and member functions together into a single unit (i.e. Class) is called Encapsulation.
Polymorphism It means one name and many duties. Polymorphism refers to the ability of one thing to take many(Poly) distinct forms(Morphism).
Constructor A constructor is a special method that is called whenever an object is created using the new keyword.
Access Modifier Java provides us a many number of access modifiers to set access levels for class, variables, methods and constructor.
Composition Composition is a special case of aggregation. In other words, a restricted aggregation is called composition. When an object contains the other object and the contained object cannot exist without the other object, then it is called composition.
List It is the sequence of elements, or we can say collection of elements, on which user has precise control over where an elements are inserted.
ArrayList It is a dynamic data structure in which you can add or remove any number of elements and those elements are stored in ordered sequence.
LinkedList It stores data in the forms of nodes, which is divided into two parts, first part stores the data and second part points to the next node by storing the address of that node.
Vector It is type of data structure that implements List Interface. It is very much similar to ArrayList as it also maintains insertion order, that is elements are retrieved in same order as they are added into it.
Map It is the mapping between a key and a value i.e. it contains values based on the key. Each key value pair is often known as an entry, As Map contains only unique keys, we can also say Map interface maps unique keys to its corresponding values.
HashMap It is a type of Collection, that stores our data in a pair such that each element has a key associated with it. The pair of key and value is often known as Entry and these entries can have only unique keys.
LinkedHashMap In Addition to all the functionalities of HashMap Class, the functionality of maintaining the insertion is added into LinkedHashMap and to attain this  functionality all the entries(key and value) are linked to each other using doubly-linked list.
TreeMap It can  stores only unique elements, that is duplicate values are not allowed and it cannot store key as null but is can  store null values. It is mostly similar to HashMap and key difference is it maintains an increasing order according to the key value.
Set It is the group of elements, or we can say collection of elements, that can never contains Duplicate element.
HashSet It is a type of Java Collection that implements the Set Interface and extends AbstractSet Interface. It uses Hash table for storing the data.
LinkedHashSet It is a type of Collection, which takes all the functionalities of HashSet class, that it does not allow duplicate elements to be stored and allow null elements in it.
TreeSet In TreeSet all the values are stored in there natural order, like all integer values are stored in ascending order and strings are stored according to Dictionary values. Apart from adding this functionality of maintaining natural ordering, Tree Set do not allow null values.
Iterator Java Iterator is an Interface that belongs to the collection framework allow us to traverse the collection objects and access the elements of  that collection.
ListIterator Special type of Iterator that is only for List Interface is known as ListIterator

Learn Android Programming – For Beginners To Pro

Android is the most popular open source operating system for mobile devices like Smartphone and Tablet. This OS is based on Linux kernel which is currently developed by Google. At Google I/O 2014, it was revealed that more than one billion per month people actively uses Android. As of July 2015, Statista revealed Google play is the largest mobile App store which has over 1.6 million Apps and billions of application gets downloaded every year. Android programming is based on Java programming language so if you have basic understanding on Java programming then it will be a fun to learn Android application development.


Prerequisite For Android Programming:

Before you begin Android programming below are the prerequisite needed:

JAVA:

Android programming is mostly done in JAVA language. So before you begin Android programming you must be comfortable with JAVA and OOPS concepts. If you are new to Android we recommend you to check out our JAVA for Android developer section where we have shared in-depth tutorial on JAVA.

XML:

Once you are done with JAVA the next thing you need is basic knowledge of XML for designing UI of Android App. Even though Android Studio has drag and drop for designing UI but still you will need to learn XML if you want your UI is highly user interactive. You can check out Design Android User Interface section to learn it.


Android Programming Tutorials:

Below are the list of Android programming topics. Follow the link to read full tutorial:

Topics (Follow the link to read tutorial) Description
Activity Lifecycle Learn about Android Activity lifecycle like created, started, resumed, paused, stopped or destroyed.
Intent Learn how Intent is used for communicating between the components of an Application and from one app to another
Shared Preference Learn how primitive data is saved on Android device based on key-value pair
JSON Parsing JSON stands for JavaScript Object Notation. It is structured, light weight, human readable and easy to parse. It’s a best alternative to XML when our android app needs to interchange data from server.
Toast & Custom Toast In Android, Toast is used to display information for a period of time. It contains a message to be displayed quickly and disappears after specified period of time.
Internal Storage In this tutorial we are going to learn about internal storage of data/files in Android App using example or you can say the primary memory of your phone.
External Storage In this tutorial we gonna study about storage of data/files in android external storage or you can say the secondary memory/SD card of your phone.
Sqlite SQLite is a Structure query base database, open source, light weight, no network access and standalone database. Android has built in SQLite database implementation.
AsyncTask In Android, AsyncTask (Asynchronous Task) allows us to run the instruction in the background and then synchronize again with our main thread.
Splash Screen Splash Screen is most commonly the first startup screen which appears when App is opened.
Volley Volley is a HTTP library developed by Google and was first introduced during Google I/O 2013. This library is used to transmit data over the network.
Retrofit Retrofit is a simple network library that used for network transactions. By using this library we can seamlessly capture JSON response from web service/web API.

 Android Material Design Tutorials With Examples

Android UI, Layout & Material Design Tutorial, With Examples

Creating an Android Virtual Device (AVD) in Android Studio

Android Material Design Tutorials With Examples

Capture

Material Design is a design language created for Google Android’s new OS which was announced in Summer 2014.  Since then it has become popular in designing and developing Android Apps. As per Google this language is based on paper and ink.

Android provides the following elements for you to build material design apps:

  • A new theme
  • New widgets for complex views
  • New APIs for custom shadows and animations

Here our in-depth tutorial will teach how to design beautiful and user friendly Application using Android Material Design. All our tutorial will have practical example and step by step explanation of each topic.


Prequisites For Leaning Android Material Design:

JAVA For Android Developer:

JAVA is a programming language which is most commonly used in Android App Development. Before you start learning Material Design you will need to learn Object Oriented Java. Check out our JAVA for Android Developer section to learn it.

Android UI Basics:

You will also need to be familiar with Android UI basics.

Android Studio:

Android Studio is the official IDE (integrated development environment) for developing Android Apps by Google. It is available for free download on Windows, Mac OS X and Linux.

Check out our Android Studio guide to get started with it.


Android Material Design Tutorials:

Below are the list of Material design topics. Follow the link to read full tutorial:

 
Topics (Follow the link to read tutorial) Description
TextInputLayout / Floating Labels in EditText TextInputLayout is a new element introduced in Design Support library to display the floating label in EditText.
TabLayout TabLayout provides horizontal layout to display tabs on the screen. We can display more screens in a single screen using tabs.
NavigationDrawer Navigation drawer is a side menu that helps us to organise the navigation inside our app. It is a uniform way to access different pages and information inside our app.
PercentRelativeLayout PercentRelativeLayout in Android is a subclass of RelativeLayout that supports percentage based margin and dimensions for Views(Button, TextView or any other view).
Toolbar In Android Toolbar is similar to an ActionBar(now called as App Bars). It is a Viewgroup that can be placed at anywhere in the Layout. We can easily replace an ActionBar with Toolbar.
PercentFrameLayout In Android PercentFrameLayout is a subclass of FrameLayout that supports percentage based margin and dimensions for Views(Button, TextView or any other view).
RecyclerView As ListView The RecyclerView is more flexible, powerful and a major enhancement over ListView.
RecyclerView As GridView The RecyclerView is more flexible, powerful and a major enhancement over GridView.
RecyclerView As StaggeredGrid It is used to show the items in staggered Grid (varying size)
CardView In Android, CardView is another main element that can represent the information in a card manner with a drop shadow called elevation and corner radius which looks consistent across the platform.
Pull To Refresh / SwipeRefreshLayout In Android App Pull To Refresh aka SwipeRefreshLayout is used whenever we need to refresh the content’s of a view via a vertical swipe gesture.
ViewPager ViewPager in Android is a class that allows the user to flip left and right through pages of data. This class provides the functionality to flip pages in app.
Animation The Animations Framework allows us to create visually attractive animations and transitions in our apps.

Android UI, Layout & Material Design Tutorial, With Examples

hhh

All user interface elements in an Android app are built using View and ViewGroup objects. A View is an object that draws something on the screen that the user can interact with. A ViewGroup is an object that holds other View (and ViewGroup ) objects in order to define the layout of the interface. Android UI designing can be done either in XML or programmatically in application. But the Android UI designer mostly prefer XML for defining UI because it separate the presentation from the code and makes easier to visualize, manage, edit and debug the App.

Here our in depth tutorial will teach you Android UI designing step by step starting with XML basic, layout, widgets and attributes with examples. Following it you will learn different UI Design techniques, patterns & principles and finally we will show you lots of examples where we will discuss designing of different Apps from scratch to finish.

 


Prerequisites For Designing Android User Interface:

Android Studio And SDK:

Android Studio is the official IDE for developing Android App created by Google. It has a very simple layout editor which support drag and drop for designing UI where one can drag layout, widgets, text fields etc. and drop it on the Virtual mobile screen to design Android UI. It also has the properties option where one can easily fill attribute like color, text etc to give attractive and pretty look to UI. The Studio also has Text option where one can see the XML code of the UI and edit it.

If you are new to it then check our Android Studio guide


Android Designing Tutorial:

New to Android UI? Begin from here.

Basics of XML In Android

Layout in Android:

Layout – Layout are used to define the actual User interface of application. It holds all the elements (i.e. views) or the tools that we want to use in application. For example, ImageView, Button,TextView and other UI elements.

Types Of Layout And Few Important ViewGroup In Android

  1. Linear Layout
  2. Relative Layout
  3. Table Layout
  4. FrameLayout
  5. Absolute Layout
  6. ConstraintLayout

  7. WebView

  8. ListView
  9. GridView
  10. Recycler View

Also Read: Nested Layout in Android

Adapter In Android:

Adapter – Adapter acts as a bridge between UI component and data source that helps us to fill data in UI component. It holds the data and send the data to an Adapter view then view can takes the data from the adapter view and shows the data on different views like as ListView, GridView, Spinner etc.

Different types of Adapter in Android:

  1. BaseAdapter
  2. SimpleAdapter
  3. Custom SimpleAdapter
  4. ArrayAdapter

Important Android UI Tutorials

List of all  Android UI tutorials

Also Read:

1. UI for Multiple Screens.

2. Responsive UI with ConstraintLayout.

3. Adding App Bar.

4. Showing pop up messages.

5. Creating custom layout.

6. Creating Backward-Compatible User Interface.

7. Implementing Accessibility.

8. Managing the System User Interface.

9. Creating Apps with Material Design.

 
Topics (Follow the link to read tutorial) Description
ListView It helps in displaying the data in the form of a scrollable list.
GridView It display items in two dimensional scrolling grid (rows and columns), the grid items are not necessarily predetermined but they are automatically inserted to the layout using a ListAdapter.
ScrollView And Horizontal ScrollView It is used to scroll the items in vertical direction and Horizontal ScrollView scroll the items in horizontal direction
Spinner Spinner provides a quick way to select one value from a set of values. Android spinners are nothing but the drop down-list seen in other programming languages.
Custom Spinner When we want to display a spinner item with image, text etc
TextView It display text to the user
EditText It provide an input or text field where user can enter something like his name details, phone number etc
Button It is a push button which can be clicked, or pressed by the user to perform an action
ImageView It is used to display an image file in application
ImageButton It is used to display a normal button with a custom image in a button
CheckBox It is a type of two state button either unchecked or checked in Android.
Switch It is off/on button which indicate the current state of Switch. It is commonly used in selecting on/off in Sound, Bluetooth, WiFi etc.
RadioButton And RadioGroup In Android, RadioButton are mainly used together in a RadioGroup. In RadioGroup checking the one radiobutton out of several radio button added in it will automatically unchecked all the others.
RatingBar It is used to get the rating from the app user.
WebView It is a view which is used to display the web pages in application.
AutoCompleteTextView It is a view i.e similar to EditText, except that it displays a list of completion suggestions automatically while the user is typing.
MultiAutoCompleteTextView MultiAutoCompleteTextView is similar to AutoCompleteTextView except that it can hold multiple string words value at single time
ProgressBar It is used to display the status of work being done like analyzing status of work or downloading a file etc.
Timepicker It is a widget used for selecting the time of the day in either AM/PM mode or 24 hours mode
DatePicker It is a widget used to select a date by day, month and year
Calendar View It is used for displaying Calendar and selecting dates
AnalogClock, DigitalClock And TextClock AnalogClock is a two handed clock one for hour indicator and the other for minute indicator and DigitalClock & TextClock both looks like your normal digital watch on hand which displays the hours minutes and seconds in digital format
SeekBar It is an extension of ProgressBar that adds a draggable thumb, a user can touch the thumb and drag left or right to set the value for current progress
ExpandableListView It is a View that shows items in a vertically scrolling two level list
Chronometer It implements a simple timer
ZoomControls It display simple set of controls that is used for zooming and provides callback to register for events
CheckedTextView It is an extension of normal TextView that supports the checkable interface and displays it
VideoView It is used to display a video file
TabHost It is a Container for tabbed window view. Whenever we need to enter or display a lot of information in one activity. A simple and effective method is to use tabs in your interface form which is done using TabHost in Android.
SearchView It provide search user interface where users can enter a search query and then submit a request to search provider
SlidingDrawer It is used to hide the content out of the screen and allows the user to drag a handle to bring the content on screen
TextSwitcher It is used to animate a label(i.e. text) on screen
ViewSwitcher It is used for switching between views which can hold only two child views for switching
ViewFlipper ViewSwitcher can hold only two child views but ViewFlipper can holds two or more child views and show one at a time
ViewStub It is a zero sized invisible View that can be used to lazily inflate layout resource at runtime
Gallery It is a view used to show items in a center locked, horizontally scrolling list and user will select a view and then user selected view will be shown in the center of the Horizontal list
CountDownTimer CountDownTimer in Android is used to set a countdown based on interval set by you and it will stop when the time has come in future.
Alert Dialog Alert Dialog in an android UI prompts a small window to make decision on mobile screen. Sometimes before making a decision it is required to give an alert to the user without moving to next activity.
ProgressDialog Android Progress Dialog is a UI which shows the progress of a task like you want user to wait until the previous lined up task is completed and for that purpose you can use progress dialog.
HTML in Android In Android, many times while designing an application we might be in a situation where we would like to use HTML content and display in our App screen. It may be to display some static content like help, support, FAQ and others pages.

Creating an Android Virtual Device (AVD) in Android Studio

An Android Virtual Device (AVD) is a configuration that defines the characteristics of an Android phone, tablet, Android Wear, or Android TV device that you want to simulate in the Android Emulator. Before debugging and testing android application, you should create an android virtual device ( AVD ) to start a simulator. You can specify special configurations for your avd, and then start it for debugging and executing applications.

To create a new AVD, do one of the following:

  • Select Tools > Android > AVD Manager.
  • Click AVD Manager AVD Manager icon in the toolbar.

Both will Open the AVD Manager shown in figure below:

1

OR

2

Android Virtual Device Manager will be opened. After that Click on Create Virtual Device.

3

Now choose the Category, phone size and choose the pixels according to your requirement. After this click on Next button.

4

After that choose the SDK Version and Click on Next button. If you have various SDK Versions like Kitkat, Lolipop ,Marshmallow,Nougat and Oreo etc in your SDK then you can select one of them. Here we choose Nougat SDK Version. Click on the next.

5

After that Enter the AVD Name in Android Virtual Device and Click on Finish button. Here you can do customization to AVD which you are creating as per your requirement.

Click Finish and new AVD is created. To start it, click the green triangle button in AVD list Actions column. To edit it’s settings, click the green pencil button.

6

AVD will start in Emulator. Now you can run your App in this AVD.

emulator2

I hope you find this blog post very helpful while creating AVD in Android Studio. Let me know in a comment if you have any questions regarding Android Studio. I will reply you ASAP.

 

 

 

 

Add/Create New Java Class in Android Studio

What is Java Class ?

A class is nothing but a blueprint or a template for creating different objects which defines its properties and behaviors. Java class objects exhibit the properties and behaviors defined by its class. A class can contain fields and methods to describe the behavior of an object.

Android Studio helps you to quickly create the following new classes and types:

  • Java classes
  • Enumeration and singleton classes
  • Interface and annotation types

Step 1:  Firstly, Select app > Java > package > Right Click on package. After that Click on New > Java Class.

1

Step 2: After that Enter Class name and Click on OK. Here we create Class Bird as shown in figure below. Remember to choose your package in which you want to create new class. There are many options available fill as your requirement.

2

New Java Class will be created in your Android project.

3

 

I hope you find this blog post very helpful while creating Android Project in Android Studio. Let me know in a comment if you have any questions regarding Android Studio. I will reply you ASAP.

Add a new activity to an existing project in Android Studio

Step 1: Firstly, right-click the app folder and select New > Activity  and choose your Activity as per requirement. Here I choose Login Activity as shown in figure below.

1

Step 2: After that Customize the Activity in Android Studio. Enter the “Activity Name”, “Layout Name”, “Title” ,”Hierarchical Parent”, “Package name”,”Source Language” and “Target Source Set ” in the Text box and Click on Finish button.

Note: Default configuration works fine.

All steps are shown in figure in below:

2

To configure Hierarchical parent click on right three doted  button. Here I choose MainActivity but you can choose as your requirement.

3

If you want to write program in kotlin click Source Language and set to kotlin. Default source language  is Java in android Studio 3.

4

5

To set Target Source Set click on target source set It will show three option.By default it set to main in android studio 3.

6

Step 3: After that your new Activity in Layout will be created. Your XML Code is in Text and your Design Output is in Design. See below figure.

7

 

Close, Save and Open Recent project in Android Studio

Open Project in Android Studio

Understanding PHP Generator With Example

phpgen

Overview Of Generators:

Generator does not returns a value but generates a sequence of values. It is a normal function that instead of returning a value yields as many values as needed to get a desired result.

A generator allows you to write code that uses foreach to iterate over a set of data without needing to build an array in memory, which may cause you to exceed a memory limit, or require a considerable amount of processing time to generate.

A generator function looks just like a normal function, except that instead of returning a value, a generator yields as many values as it needs to.

The heart of a generator function is the yield keyword. In its simplest form, a yield statement looks much like a return statement, except that instead of stopping execution of the function and returning, yield instead provides a value to the code looping over the generator and pauses execution of the generator function.

A Simple Generator:

<?php

function gen_one_to_ten(){

for($i=1;$i<=10;$i++){

yield$i;

}

}

$gen=gen_one_to_ten();

foreach($gen as $value){

echo"$value\t";

}

?>

Fibonacci Generator Example:

<?php

function fib($n)

{

$cur=1;

$prev=0;

for ($i=0; $i<$n; $i++) {

yield$cur;

$temp=$cur;

$cur=$prev+$cur;

$prev=$temp;

}

}

$fibs = fib(9);

foreach ($fibs as $fib) {

echo" ".$fib;

}

// prints: 1 1 2 3 5 8 13 21 34
?>

 

Close, Save and Open Recent project in Android Studio

When the project is already opened in android studio and the same time you want to open another project  in android studio then use the File>> Open Recent. When the project work is done in android studio to close  project use the File>>Close project and to save project in android studio  use the Save All option from the File>>Save All.

  Open Recent project in Android Studio:

Firstly, Click on File then Click on Open Recent and choose the file which file you want to be opened. I choose “MathGame” file.

1

After that a message box will be shown on your computer screen. This will show  project will be opened in “This Window” or “New Window”. I open the project in “This Window” and After that your project will be opened.

2

Close project in Android Studio:

To close project you need click ” File —> Close Project ” menu in top menu bar.

3

Save project in Android Studio:

To save project, you need to click ” File —> Save All ” menu in top menu bar or just click Ctrl+S.

4

To remove project completely from Android Studio, just to File->Close Project, then, in the “Welcome to Android Studio” window, you have an “x” right next to each project; just press it to remove it from the recents.

5

I hope you find this blog post very helpful while creating Android Project in Android Studio. Let me know in a comment if you have any questions regarding Android Studio. I will reply you ASAP.