Skip to main content

Posts

Showing posts with the label broadcast receivers

Interview Questions 31 -- 40

What is the importance of having an emulator within the Android environment? The emulator provides an interface that acts as if it were an actual mobile device. They can write and test codes, and even debug. Emulators are a safe place for testing codes especially if it is in the early design phase. Differentiate Activities from Services. Activities can be closed, or terminated anytime the user wishes. On the other hand, services are designed to run behind the scenes, and can act independently. Most services run continuously, regardless of whether there are certain or no activities being executed. What are containers? Containers, as the name itself implies, holds objects and widgets together, depending on which specific items are needed and in what particular arrangement that is wanted. Containers may hold labels, fields, buttons, or even child containers, as examples. What is Orientation? Orientation, which can be set using setOrientation(), dictates if the LinearLayout is...

Interview Question 21 - 30

See more basics on Android along with interview questions Explain about the Android Exceptions ? The following are the exceptions that are supported by Android InflateException :         When an error conditions are occurred, this exception is thrown Surface.OutOfResourceException:         When a surface is not created or resized, this exception is thrown SurfaceHolder.BadSurfaceTypeException:          This exception is thrown from the lockCanvas() method, when invoked on a Surface whose is SURFACE_TYPE_PUSH_BUFFERS WindowManager.BadTokenException:          This exception is thrown at the time of trying to add view an invalid WindowManager.LayoutParamstoken. What is Drawable? A compiled visual resource that can be used as a background, title, or other part of the screen. It is compiled into an android.graphics.drawable subclass. What is an Intent Receiver? An a...

Interview Questions 11 -- 20

See more basics on Android along with interview questions Talk on Android OS ?                  Android is a Linux-based operating system designed primarily for touchscreen mobile devices such as smartphones and tablet computers. Initially developed by Android, Inc., which Google backed financially and later bought in 2005.Android is the world's most popular mobile platform. Android is a Linux-based mobile phone operating system developed by Google. Android is unique because Google is actively developing the platform but giving it away for free to hardware manufacturers and phone carriers who want to use Android on their devices. What is Android SDK ?                 A software development kit that enables developers to create applications for the Android platform. The Android SDK includes sample projects with source code, development tools, an emulator, and required libraries to build An...

Interview Questions 1 -- 10

See more basics on Android along with interview questions What is definition of Android ?                Android is a software stack for mobile devices that middleware, operating systems,    and application-specific key. The application must be implemented in its own process    and the Dalvik virtual machine interface. DVM is used effectively run multiple virtual    machines. Java byte code is executed which is converted file format called Dex. How the data will be stored in Android or types of data stored in Android ?    Internal Storage   Connecting to a network    General preferences    SQLite database   External Storage What are the components of Android Application ?                Android is written in java programming language.Android application are composed of       some of the main com...

Android Application Fundamentals or Components

See more basics on Android along with interview questions Android is written in java programming language.Android application are composed of some of the main components such as: Activities Services Content providers Broadcast receivers Intents, Resources(such as strings and graphics), Notification signalings(light,sound,dialog), are also part of the components. All these components play different role in the overall application and each one can be activated individually. Activities :           An activity represents a single screen with a user interface.Suppose if there is a listview and if clicking on each row it traverse to another page ,then the screen showing listview is an activity and the next page is another activity,where each one is independent of the others. An activity is implemented as a subclass of Activity ,that why we use see activity life cycle here : public class MainActivity extends Activity { } ...

BroadcastReceiver for Screen On/Off in ANDROID

If wanted to call a broadcast for screen on/off you can get the code sniffet from here. Here I have used dynamic calling of Broadcast and the java source code is given below. get more details about broadcast from :    Broadcast Receiver Introduction in Android    BroadcastReceiver to get Battery Level in java file: public class MainActivity extends Activity { //Create broadcast object BroadcastReceiver mybroadcast = new BroadcastReceiver() { //When Event is published, onReceive method is called @Override public void onReceive(Context context, Intent intent) { // TODO Auto-generated method stub Log.i("[BroadcastReceiver]", "MyReceiver"); if(intent.getAction().equals(Intent.ACTION_SCREEN_ON)){ Log.i("[BroadcastReceiver]", "Screen ON"); } else if(intent.getAction().equals(Intent.ACTION_SCREEN_OFF)){ Log.i("[BroadcastReceiver]", "Screen ...

BroadcastReceiver to get Battery Level - simple Example using dynamic calling of BroadCast in ANDROID

See Introduction for Broadcast Receiver here:  When you need to call a broadcast (suppose here battery value) you need to register the broadcast and when the event is published it will call onReceive method which have context and particular intent as parameter. public class Broadcast extends Activity { //Create broadcast object BroadcastReceiver mybroadcast = new BroadcastReceiver() { //When Event is published, onReceive method is called @Override public void onReceive(Context context, Intent intent) { //Get battery percentage int batterylevel = intent.getIntExtra("level", 0); //get progressbar ProgressBar myprogressbar = (ProgressBar) findViewById(R.id.progressbar); myprogressbar.setProgress(batterylevel); TextView tv = (TextView) findViewById(R.id.textfield); //Set TextView with text tv.setText("Battery Level: " + Integer.toString(batterylevel) + "%"); } }; @Override p...

Broadcast Receiver Introduction in Android

A broadcast receiver is a component that responds to system-wide broadcast announcements. Many broadcasts originate from the system—for example, a broadcast announcing that the screen has turned off, the battery is low, or a picture was captured. There are two ways to use broad cast receiver in android -- One is using dynamically in activity Second to register through manifest Using dynamically in activity Register broadcast receiver Via dynamically ( Run time ) // Create reciever object private BroadcastReceiver the_receiver = new PhoneCall(); // Set When broadcast event will fire. private IntentFilter filter = new IntentFilter(Intent.ACTION_CONFIGURATION_CHANGED); // Register new broadcast receiver this.registerReceiver(the_receiver, filter); // Reciever class which extends BroadcastReceiver public class PhoneCall extends BroadcastReceiver { public void onReceive(Context context, Intent intent) { // Phone call state change then this method will au...