0% found this document useful (0 votes)
47 views

Android Tutorial Basics PART I II

The document provides an overview and tutorial on Android app development. It covers topics like installing Android Studio, the Android architecture including components, compiling an Android app, and an overview of Android Studio. It then discusses how to create a basic "Hello World" app in Android Studio including formatting text, adding buttons, showing toasts, handling click events, and displaying alerts. It also covers opening a second activity, passing data between activities, and working with images.

Uploaded by

Fallen Angel 101
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
47 views

Android Tutorial Basics PART I II

The document provides an overview and tutorial on Android app development. It covers topics like installing Android Studio, the Android architecture including components, compiling an Android app, and an overview of Android Studio. It then discusses how to create a basic "Hello World" app in Android Studio including formatting text, adding buttons, showing toasts, handling click events, and displaying alerts. It also covers opening a second activity, passing data between activities, and working with images.

Uploaded by

Fallen Angel 101
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 44

Tutorial On

“Android App Development”


By
Vikas Soni
PART - I
Index
PART - I
1. Installation of android studio
2. Android architecture
3. Android components
4. Android Program compilation process
5. Android Studio overview
(Project explorer and components)
(Inserting Java file and write XML file with Label)
(Build the project and generate APK)
(Test the APK)
(Debug the app)
6. Run the app on full screen (Without Action bar) and Create the App icon
7. Creating first activity Format the text
8. show toast on activity load
9. Handle the event
10. Show alert message.
11. Creating Dummy Login validation activity
12. Post Login data to other activity
13. Working with image
14. Working with constraint, relative and Linear layout
15. Open second activity using intent
16. Passing the data using intent
17. Setting the launcher activity before main activity
18. Setting the permission in manifest file
19. Opening the account on play store
20. Generating the APK for upload to play store
Android Architecture
• android architecture or Android software
stack is categorized into five parts:
– linux kernel (like DOS of windows)
– native libraries (middleware)(Mic-drivers written
c/c++)
– Android Runtime (Like JRE)
– Application Framework (Premade sw collection)
– Applications
Android Architecture
Android Architecture
• Linux kernel - It is the heart of android architecture that
exists at the root of android architecture. Linux kernel is
responsible for device drivers, power management,
memory management, device management and resource
access.
• Native Libraries - On the top of linux kernel, their
are Native libraries that works for physical device
components like sensors, touch input, internal SQlite
database, C/C++/Java libraries and to modify these native
libraries a tool called NDK(Native Development Kit) is
used (Normally this is not used by normal programmers)
• In easy way the native libraries contains base code for
additional functions and control of physical device
components apart from kernel.
Android Architecture
• Android Runtime - In android runtime, there are core
libraries and DVM (Dalvik Virtual Machine) which is
responsible to run android application. DVM is like JVM
but it is optimized for mobile devices. It consumes less
memory and provides fast performance.
• Android Framework - On the top of Native libraries and
android runtime, there is android framework. Android
framework includes Android API's such as UI (User
Interface), telephony, resources, locations, Content
Providers (data) and package managers. It provides a
lot of classes and interfaces for android application
development.
Android Architecture
• Applications - On the top of android
framework, there are applications. All
applications such as home, contact, settings,
games, browsers are using android framework
that uses android runtime and libraries.
Android runtime and native libraries are using
linux kernal.
Android Program Compilation
(Dalvik Virtual Machine | DVM)
• The Dalvik Virtual Machine (DVM) is an android virtual
machine optimized for mobile devices. It optimizes the
virtual machine for memory, battery life and performance.
Android Application Components
• All the android app made by using following
components -
– Activity – GUI Made for User.
– Services – That Runs in Background.
– Broad Cast Receiver – To generate system-wide broadcast
announcements.
– Content Provider - A content provider manages a shared set
of app data like your contacts in phone book.
– Intent – is a component that is used to start something like
• Start the service
• Launch an activity
• Display a web page
• Display a list of contacts
• Broadcast a message
• Dial a phone call etc.
Android Project Structure
Android Studio Project Structure
Property Window
Project Explorer

Design View
UI Widgets and tools

Component View
Android Studio Project Debugging
Android Studio Project Debugging
Note
If your crashes suddenly while opening
that means there is some error in your
“Java file or Menifest” file code. To
debug that crash verify the code
carefully and take help from debug
and log consol.
Creating the project
Building and Testing the app with
default
• Build the project
• Go to Project folder->app->build->output->apk
• Copy the .apk file to your phone
• Allow install app from unknown source option
• Install and run the app
Creating the app icon and change the
theme with no action bar
• Go to Project folder->app->source>main->res
• Navigate to mip-map folder
• Copy your icon
• Go to menifest file and specify name of your
icon file
Creating the app icon and change the
theme with no action bar

• Go to menifest file and specify name of your


icon file and change theme
Create activity and format the
TextView
• Add the TextView in constraint layout and set the margin to remove
constraint error
• Do following formatting by accessing the properties of label widget.
– ID
– Text
– Text appearance
– Text color
– Text Size
– Font Family
– Text Style
– Layout height and Width as match parent with zero margin
– Gravity to set alignment
– Padding
– Background
– Alpha to set transparency
Show Toast Message
public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

Toast.makeText(this,"This is Test
Msg",Toast.LENGTH_SHORT).show();

}
}
Handle The Click Event of Button
•Draw the button in XML file and set ID of button
•Now set Text of Button and set any event name like
“Clickme” in Onclick property option then write java
code
public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void clickme(View view)
{
EditText name=(EditText)findViewById(R.id.et_name);
String name1=name.getText().toString();
Toast.makeText(this,"Your Name is : "+name1,Toast.LENGTH_SHORT).show();
}
}
Alert Dialog
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
new AlertDialog.Builder(this)
.setIcon(android.R.drawable.ic_dialog_alert)
.setTitle("Are you sure!?")
.setMessage("Do you definitely want to do this?")
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
Toast.makeText(MainActivity.this,"It's
done!",Toast.LENGTH_SHORT).show();
}
})
.setNegativeButton("No",null)
.show(); }}
Dummy Login
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void clickme(View view)
{
EditText name=(EditText)findViewById(R.id.editText);
EditText pass=(EditText)findViewById(R.id.editText);
String namestr=name.getText().toString();
if(namestr.equals("vikas"))
{
Toast.makeText(this,"Welcome",Toast.LENGTH_SHORT).show();
}

}
}
Open Second Activity With Post Values
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void clickme(View view)
{
EditText name=(EditText)findViewById(R.id.editText);
EditText pass=(EditText)findViewById(R.id.editText);
String namestr=name.getText().toString();
if(namestr.equals("vikas"))
{
Intent i=new Intent(getApplicationContext(),DisplayInfo.class);
i.putExtra("value1",namestr);
startActivity(i);
}}
}
Open Second Activity With Post Values..
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.displayinfo);
Bundle extras=getIntent().getExtras();
String val1=extras.getString("value1");
Toast.makeText(getApplicationContext(),"First
value"+ val1,Toast.LENGTH_SHORT).show();
TextView
showuser=(TextView)findViewById(R.id.textview);

showuser.setText(val1);
}
}
Working With Images
Add two images in XML file one over other and set onclick value in top image then go to
Java file and write the code

public class MainActivity extends AppCompatActivity {


@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.displayinfo);
}
public void clickme(View view)
{
ImageView img=(ImageView)findViewById(R.id.imageView2);
img.setVisibility(View.INVISIBLE);
}
}
Setting up the Launcher Activity
To make any activity as a launcher activity just cut this code shown in blue and paste
in your activity opening and closing TAG in Manifest file.

<activity android:name=“…Youractivityname…">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category
android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Setting up the Permissions
Go to Manifest file and add line for permission like below
Upload App on Play Store
Create Account 1st
Upload App on Play Store
Generate Signed APK for Upload
End of PART - I
PART - II
Index
1. Live login activity using SQLite
Database
2. Working with animation
3. Working with Audio
4. Working with Video
5. Working with Grid Layout
6. Working with Webview
7. Error Handling
8. Decompiling the existing App
9. Missellanous
Login and Signup Activity
• Make an activity with two edit text, two button for login and signup
• 1st create Database, write following code in on create method of
activity.

public class dummylogin extends AppCompatActivity {


SQLiteDatabase db;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_dummylogin);
db=this.openOrCreateDatabase("mydb",MODE_PRIVATE,null);
db.execSQL("create table if not exists user (name varchar,pass
varchar)");
}}
Login and Signup Activity
• write following code in onclick method of signup button.

public void signup(View view)


{
EditText name=(EditText)findViewById(R.id.et_name);
EditText pass=(EditText)findViewById(R.id.et_pass);
String namestr=name.getText().toString();
String passstr=pass.getText().toString();
db.execSQL("insert into user (name,pass)
values('"+namestr+"','"+passstr+"')");
Toast.makeText(this,"Record
inserted",Toast.LENGTH_SHORT).show();
}
Login and Signup Activity
• write following code in onclick method of login button.
public void login(View view)
{
EditText name=(EditText)findViewById(R.id.et_name);
EditText pass=(EditText)findViewById(R.id.et_pass);
String namestr=name.getText().toString();
String passstr=pass.getText().toString();
Cursor c=db.rawQuery("select * from user",null);
int passindex=c.getColumnIndex("pass");
int nameindex=c.getColumnIndex("name");
c.moveToFirst();
String dbpass="";
String dbname="";
int counter=0;
while(!c.isAfterLast())
{
dbpass=c.getString(passindex);
dbname=c.getString(nameindex);
Log.i("name",c.getString(passindex));
if(dbpass.equals(passstr) && dbname.equals(namestr) )
{
Toast.makeText(this,"name is : "+namestr,Toast.LENGTH_SHORT).show();
Intent i=new Intent(dummylogin.this,displayinfo.class);
i.putExtra("value1",namestr);
startActivity(i);
counter++;
break;
}
c.moveToNext();
}
if(counter==0)
{
Toast.makeText(this,"Wrong UID Or PWD !!",Toast.LENGTH_SHORT).show();
}
}
Animations
• Make an activity and insert two images then set onclick event on one of the image and set alpha ‘0’
of one image and alpha ‘1’ of other and try following code in java file.
Public void imageclick(View view)
{
Boolean img=true;
Log.i(“info",”image view tapped”);
ImageView img1=(ImageView)findViewById(R.id.imageView);
ImageView img2=(ImageView)findViewById(R.id.imageView2);
If (img)
{
Img1.animate().alpha(0).setDuration(2000);
Img2.animate().alpha(1).setDuration(2000);

}
Else
{
Img1.animate().alpha(1).setDuration(2000);
Img2.animate().alpha(0).setDuration(2000);

}
}
Working With Video
Working With Audio
Grid Layout
Add a button with following code (in XML file) inside grid layout under the parent layout i.e.
constraint and multiply button code as much grid you want
<Button
android:id="@+id/button"
android:text="Button"
android:layout_gravity="fill"
android:layout_rowWeight="1"
android:layout_columnWeight="1"
/>
Error Handling
• Use the Try – Catch block to handle the errors
• Use Log.i() method like

Log.i("info","msg");

try { ... }
catch (Exception e)
{
// This will catch any exception, because they are all descended from
Exception
System.out.println("Error " + e.getMessage());
}
Working with Webview
• Add webview in your XML file give ID, then make a assett folder
copy web pages in that and then come for Java code.
wv = (WebView)findViewById(R.id.wv);
wv.setInitialScale(40);
wv.getSettings().setJavaScriptEnabled(true);
wv.getSettings().setLoadWithOverviewMode(true);
wv.getSettings().setUseWideViewPort(true);
wv.getSettings().setJavaScriptEnabled(true);
wv.getSettings().setSupportZoom(true);
wv.getSettings().setBuiltInZoomControls(true);
//use on of the below for loadurl
wv.loadUrl("http://www.brbraitt.bsnl.co.in"); or
wv.loadUrl(“file:///android_asset/samplepage.html");
wv.setWebViewClient(new WebViewClient());
App de-Compile and Compile
1. Make Folder copy apktool.jar and apk file then run command in cmd
java -jar apktool.jar d -s Appname.apk
This command will create a folder in which all resource folder, Dex
file and manifest file you can get
Now, copy dex file in dex2jar folder and run command in cmd
d2j-dex2jar classes.dex
This will give you jar file, Now open this jar file through JDGUI
application

2. To compile again run following command to get back your apk file
java -jar apktool.jar b Appfoldername

3. Download APK signer app and make a signed copy of APK so that
you can install into mobile

You might also like