Android Interview Question

What is Gradle in Android Studio?
Gradle is to the Groovy JVM language what Ant is to Java. Basically, it’s Groovy’s build tool. Unlike Ant, it’s based on the full Groovy language. You can, for example, write Groovy script code in the Gradle script to do something rather than relying on a domain-specific language.

What is Gradle in Android Studio?
Gradle is to the Groovy JVM language what Ant is to Java. Basically, it’s Groovy’s build tool. Unlike Ant, it’s based on the full Groovy language. You can, for example, write Groovy script code in the Gradle script to do something rather than relying on a domain-specific language.

What is Intent in Android?
Intents could be Implicit, for instance, calling intended actions, and explicit as well, such as opening another activity after some operations like onClick or anything else. Below are some applications of Intents:

  1. Sending the User to Another App
  2. Getting a Result from an Activity
  3. Allowing Other Apps to Start Your Activity

What is Intent Filter in Android ?

  • Implicit intent uses the intent filter to serve the user request.
  • The intent filter specifies the types of intents that an activity, service, or broadcast receiver can respond.
  • Intent filters are declared in the Android manifest file.
  • Intent filter must contain <action>

Most of the intent filter are describe by its 

  1. <action>, 
  2. <category> and
  3. <data>.
Example of Intent Filter :

<activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
  
            <!--SEND INTENT FILTER-->
            <intent-filter>
                <action android:name="android.intent.action.SEND"/>
                <category android:name="android.intent.category.DEFAULT"/>
                <data android:mimeType="text/plain"/>
            </intent-filter>
  
            <!--VIEW INTENT FILTER-->
            <intent-filter>
                <action android:name="android.intent.action.VIEW"/>
                <category android:name="android.intent.category.DEFAULT"/>
                <category android:name="android.intent.category.BROWSABLE"/>
                <data android:scheme="http"/>
            </intent-filter>
  
        </activity>
 

What is Service in Android ?
Services in Android are a special component that facilitates an application to run in the background in order to perform long-running operation tasks. 
Types of services :

1. Foreground Services:
Users can interact with the service through the notifications provided about the ongoing task. Such as in downloading a file, the user can keep track of the progress in downloading and can also pause and resume the process.

2. Background Services:
services do not notify the user about ongoing background tasks and users also cannot access them. The process like schedule syncing of data or storing of data fall under this service.

3. Bound Services:
More than one component is allowed to bind itself with a service at a time. In order to bind an application component with a service bindService() method is used

Whats is Pending Intent ?

Intent – is a message passing mechanism between components of Android, except for Content Provider. You can use Intent to start any component.

Sticky Intent – Sticks with Android, for future broadcast listeners. For example, if the BATTERY_LOW event occurs then that Intent will stick with Android so that any future requests for BATTERY_LOW, will return the Intent.
sticky intents are associated with the android system for the future broadcast events.

Pending Intent – If you want someone to perform any Intent operation at a future point of time on behalf of you, then we will use Pending Intent.
Those intent which you want to trigger at some time in future when you application is not alive.


What is Broadcast Receiver in Android ?
Generally there are two type of broadcasts there:
1. System Broadcasts
2. Receiving Broadcasts

 <receiver android:name="MyScheduleReceiver" >
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED" />
            </intent-filter>
 </receiver>     

Whats is the Content Provider in Android ?
ContentProvider is mainly used to access data from one application to another application.
For example, by using ContentProvider we can get phone contacts, and call logs from phones to our own application in android. we can also access data that are stored in (SQLite)databases.

  • onCreate() This method is called when the provider is started.
  • query() This method receives a request from a client. The result is returned as a Cursor object.
  • insert()This method inserts a new record into the content provider.
  • delete() This method deletes an existing record from the content provider.
  • update() This method updates an existing record from the content provider.
  • getType() This method returns the MIME type of the data at the given URI.

How to create own content provider in Android ?

  • First of all you need to create a Content Provider class that extends the ContentProviderbaseclass.
  • Second, you need to define your content provider URI address which will be used to access the content. [Exp, String URL = “content://com.example.MyApplication.StudentsProvider”; ]
    Convert URL to URI
    Uri students = Uri.parse(URL);
    Cursor c = managedQuery(students, null, null, null, “name”);
  • Next you will need to create your own database to keep the content. Usually, Android uses SQLite database and framework needs to override onCreate() method which will use SQLite Open Helper method to create or open the provider’s database. When your application is launched, the onCreate() handler of each of its Content Providers is called on the main application thread.
  • Next you will have to implement Content Provider queries to perform different database specific operations.
  • Finally register your Content Provider in your activity file using <provider> tag.


Activity, AppCompatActivity, FragmentActivity, and ActionBarActivity: When to Use Which?

Activity is the baseline. Every activity inherits from Activity, directly or indirectly.
AppCompatActivity is from the appcompat-v7 library. Principally, this offers a backport of the action bar. Since the native action bar was added in API Level 11, you do not need AppCompatActivity for that. 
ActionBarActivity is the old name of the base activity from appcompat-v7. For various reasons, they wanted to change the name. Unless some third-party library you are using insists upon an
FragmentActivity specifically is if you want to use nested fragments (a fragment holding another fragment), as that was not supported in native fragments until API Level 17.

So, given your minSdkVersion in the 15-16 range:

  • If you want the backported Material Design look, use AppCompatActivity
  • If not, but you want nested fragments, use FragmentActivity
  • If not, use Activity

AppCompatActivity extends FragmentActivity , so anyone who needs to use features of FragmentActivity can use AppCompatActivity.

Leave a Reply

Your email address will not be published.