Skip to main content

Posts

Applying Styles and Themes to an Activity

By default , an activity is themed to the default Android theme. However , there been a push in recent year to adopt a new theme known as Material . The Material theme has a much more modern and clean look to it. There are two versions of the Material theme available to Android developers : Material Light and Material Dark , Either of these themes can be applied from the AndroidManifest.xml To apply one of the Material themes to an activity , simply modify the <Application> element in the AndroidManifest.xml file by changing the default android:theme attribute. (Please be sure to change all instances of "com.android" to whatever package name your project is using.) <?xml version="1.0" encoding="utf-8"?> <manifest xmls:android="http://schemas.android.com/apk/res/android"        xmlns:tools="http://schemas.android.com/tools"        package="com.android.activity101">        <application ...

Understanding the Life Cycle of a Activity

1. Using Android Studio , create a new Android project and name is Activity101. 2. In the Activity101Activity.java file , add the following highlighted statements. Package com.example.activity101; import androidx.appcompat.app.AppCompatActivity; import android.os.Bundle; import android.util.Log; public class MainActivity extends AppCompatActivity {        String tag="LifeCycle Step";       @Override        protected void onCreate(Bundle savedInstanceState)        {                super.onCreate(savedInstanceState);                setContentView(R.layout.activity_main);                Log.d(tag,msg:"In the onCreate () event");        }        public void onStart()        {           ...

Understanding Activities

This blog begins by showing you to create an activity. To create an activity , you create a Java class that extends the Activity base class : public class MainActivity extends AppcompatActivity {           @Override           protected void onCreate(Bundle savedInstanceState)           {                     super.onCreate(savedInstanceState);                     setContentView(R.laout.activity_main);           } } Your activity class loads its user interface ( UI ) component using the XML file defined in your res/layout folder . In this example , you would load the UI from the main.xml file :   ...

Publishing Your Application

After you have created , and fully debugged , you application , you might want to deploy it to the Google.Store for others to enjoy. The following sections outline the steps for publishing your applications. Generating a Signed APK To Publish Your finished application on the Google Play Store , you must generate a signed APK ( the Android application package ) . The APK is the compiled , executable version of your application. Signing it is much like signing your name to a document. The signature identifies the app's developer to Google and the users who install your application. More importantly , unless your Android Studio is in developer mode , unsigned application will not run . Use the following steps to generate a signed APK :   1. Generate a signed APK from your code by selecting Build -> Generate Signed APK from the Menu bar to bring up the Generate Signed APK window as show in figure   2. Assuming you have never published an application from Andr...

Navigating Paused Code

While in debug mode , Android Studio pauses at any breakpoint that you have set . This is , as long as a breakpoint has been set on a reachable line of code (  a line of code that would be executed by system ) , Android Studio halts execution at that line until you tell it to continue. When Android Studio hits , and pauses at , a breakpoint , the circle in the margin next to the corresponding line of code changes to circle with a check mark. Once a breakpoint has been hit , the debug window opens at the bottom Android Studio , as show in Figure . The debug window contains many of the tools you use to navigate around your code. Notice the navigation buttons located in the menu bar of the debug window . The most commonly used are Step Over and Step Into . Step Over advances you to the line of code that immediately follows the one at which you are currently paused . This means that if you are paused at a method call , and you press Step Over , Android Studio executes the met...

Debugging Your Application

After you have built an application , you need to be able to debug it and see what is going on inside your code . One of the handiest ways to be able to see inside your code it through the use of break points. Breakpoints allow you to pause the execution of your code at specific location and see what is going on (or what is going wrong). Let's take a look at how to use breakpoints in Android Studio. Setting Breakpoints Breakpoints are mechanism by which you can tell Android Studio to temporarily pause execution of your code , which allows you to examine the condition of your application . This means that you can check on the values of variables in your application while you are debugging it. Also , you can check whether certain lines of code are being executed as expected - or at all. To tell Android Studio that you want to examine a specific line of code during debugging , you must set breakpoint at the line. Click the margin of the editor tab next to line of code you want...

Using Code Completion

Code completion is an invaluable tool that shows you contextual options for completing the piece of code that you are trying to write. For example, in the editor tab for the MainActivity.js file, locate the line that reads.          setContentView(R.layout.activity_main); Place your cursor after this line and press the Enter Key . On the new line , type the letter R , and then type a period, as shown here:          R. Android Studio Code Completion should display a list of values that you could use to try to complete the code statement. Figure shows what this list might look like . this is important if you are not entirely sure of the spelling of a method call or how to identify the different method signatures. NOTE if the code completion window does not open , press Ctrl + Space to force it to open. This is the same key combination used in some other IDEs for their versions of the code complet...