Android Tutorial Basics PART I II
Android Tutorial Basics PART I II
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
@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
<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.
}
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