Question d’entretien chez Heal Software Inc

Components of android? Fragments? How to send msg from Fragment to fragment? Sqlite? AIDL with code example? IntentService? ANR, How to resolve? IPC? How to pass custom obj through Intent?

Réponses aux questions d'entretien

Utilisateur anonyme

2 août 2018

Answered question in details.

Utilisateur anonyme

4 sept. 2018

Components of android? There are following four main components that can be used within an Android application − 1 Activities They dictate the UI and handle the user interaction to the smart phone screen. 2 Services They handle background processing associated with an application. 3 Broadcast Receivers They handle communication between Android OS and applications. 4 Content Providers They handle data and database management issues. ----------- Fragment ? A Fragment is a piece of an activity which enable more modular activity design. It will not be wrong if we say, a fragment is a kind of sub-activity. ----------- How to send msg from Fragment to fragment? //Put the value YourNewFragment ldf = new YourNewFragment (); Bundle args = new Bundle(); args.putString("YourKey", "YourValue"); ldf.setArguments(args); //Inflate the fragment getFragmentManager().beginTransaction().add(R.id.container, ldf).commit(); //Retrieve the value String value = getArguments().getString("YourKey"); ---------------------- SQLite ? SQLite is a opensource SQL database that stores data to a text file on a device. Android comes in with built in SQLite database implementation. -------------- AIDL with code example? AIDL facilitates to communicate between server and client. In android we cannot access memory from one process to another process. If we want to do, we can do it via primitives that operating system can understand. Android facilitates us to do this task via AIDL. package com.concretepage; interface ICalService { String getMessage(String name); int getResult(int val1, int val2); } -------------- IntentService? IntentService is a base class for Service s that handle asynchronous requests (expressed as Intent s) on demand. Clients send requests through Context.startService(Intent) calls; the service is started as needed, handles each Intent in turn using a worker thread, and stops itself when it runs out of work. ------------- ANR, How to resolve? Android applications normally run entirely on a single (i.e. main) thread. This means that anything your application is doing in the main thread that takes a long time to complete can trigger the ANR dialog because your application is not giving itself a chance to handle the input event or Intent broadcast.So in that case you can use StrictMode to help find potentially long running operations such as network or database operations that you might accidentally be doing your main thread. If you find violations that you feel are problematic, there are a variety of tools to help solve them: threads, Handler, AsyncTask, IntentService, etc.Also remember that it came from API Level 9 Example code to enable from early in your Application, Activity, or other application component's onCreate() method: StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder() .detectDiskReads() .detectDiskWrites() .detectNetwork() // or .detectAll() for all detectable problems .penaltyLog() .build()); StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder() .detectLeakedSqlLiteObjects() .detectLeakedClosableObjects() .penaltyLog() .penaltyDeath() .build()); ---------- IPC is inter-process communication. It describes the mechanism how different types of android components are communicated. ----------- How to pass custom obj through Intent? You'll need to serialize your object into some kind of string representation. One possible string representation is JSON, and one of the easiest ways to serialize to/from JSON in android, if you ask me, is through Google GSON. In that case you juse put the string return value from (new Gson()).toJson(myObject); and retrieve the string value and use fromJson to turn it back into your object. If your object isn't very complex, however, it might not be worth the overhead, and you could consider passing the separate values of the object instead.