BlogUpdater_1_27_2012.doc
Hi friends, after a long time I want to help all of you people in the below concerns.
- Architecture:
- Exception Tracking
- 2DScrollView
- C2DM
- Tools
Architecture
I know lot of you people knows about this. But, let me explain this for the other people. The structure of the project should be as shown in thebelow format.
In the above image the custom Activity is the Super Activity for all of the activities where you can add unique requirements throughout the project. i.e., Exception tracking/MenuItems handling according to currentModule etc…,
First of all we should take care about the architecture while we are starting a project which will helps you a lot in the process of project enhancements and re-usability.
package.ui: Here we need to add all the custom views that are developed. So that we can use these UI from anywhere in the project and can also be maintained same for all of your future projects.
package.util: Here we need to add all the constants and utility functions like validations for dates/times or project specific things which can be used from the project.
Dispatchmodule: This is the startup module for all the projects. So that you can easily identify the starting activity in all the projects.
Every module should have an engine. All the activities should implement CustomActivity which is there in the package.ui which is implementing Activity.
Module1,2…..n: Depending upon the project, the number of modules will be divided to manage the project with ease.
At any instant, we can know all the information about the project (i.e., Module ID, Activity ID, Stack which contains all the Activity instances which are running in the background etc…,).
NetworkHandler: We should write all the handlers which can give the project running status information. Every time we starting a module/activity, this class should be intimated with the corresponding information.
Exception Tracking:
Here is a simple class file which will be very useful to track your Android applications even after sending it to the client or to the market or to the testers. This class will always track your application and it will get informed with all the exceptions (even if it is a Force Close).
How to use this:
- Just copy and paste the downloaded java file in to your project.
- Create an instance for this activity in the CustomActivity as shown below.
protected PostMortemReportExceptionHandler mDamageReport = new PostMortemReportExceptionHandler(this);
- Just to start the exception tracking.
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); mDamageReport.initialize();
}
- Closing/Stopping the tracker in the Activity.
protected void onDestroy() {
mDamageReport.restoreOriginalHandler();
mDamageReport = null;
super.onDestroy();
}
Every thing done. You can get updated with crash or exceptions.
Customizing the Tracker:
We can customize the way of getting the information of the exception or crash from the mobile device to the server. Either we can go for creating a specific web service to catch the crash report or else we can go for mail option in which we can respect the user’s privacy and can ask for his permission to send the mail.
private static final int SENDING_OPTION = 1;// 0 --> Send Through Mail (Need user interference)
// 1 --> Sending without user interference or confirmation
By using this variable, we can select the options wether we can directly post it to our webservice or to take the user's permission by preparing a mail and asking him to send it.
if we want to send it to a mail id the we can specify the mail id for the below variable
// This is the webservice URL which is used to post the issue info
2DscrollView:
In Android, we should not add a scrollview to another scrollview. Because, If we add in such a way then it will leads to the memory issues. If you want both horizontal and vertical scrolls for a single view, then you should go for a CustomFrameView.
For further information about the 2Dscroll view please click on the below link.
C2DM:
Cloud To Device Messaging is a concept which is introduced in Android from OS version 2.2. The concept of C2DM is to optimize the network usage of the Android applications in push notifications.
Normally for every application, in order to get the push notifications, we should have a separate thread /service running in the background of the operating system continuously hitting the server in equal intervals of time which will drains the battery of the device and unnecessary usage of network. If we want push notifications for ‘n’ number of applications, then we should run ‘n’ number of services to get the notifications for n applications.
For every Android device, there will be default Google service running in the background which will take care about all the Google applications in device. After 2.2, they gave us an option to use the same Google service. So, that there is no need of running separate threads for each and every application.
We should send the desired message with the device ID to the Google C2DM server. then, the message will be sent to the device from the Google C2DM server.
We can get the device ID from the device after registering it to the Google C2DM server. We should send this ID from device to our Application third party Server. Then after, the application server will send the message to that specific device by using this device ID.
The device ID will be updated every time when the Google server get refreshed. Then the Google server will automatically send a broadcast message to the device and then we should get the device ID again and should intimate about the change of the Device ID to application third party server. So, that the application server will send the messages by using the updated device ID.
I will update this later by adding the code snippets later.
TOOLS:
DDMS:
This is used to fetch the logs, process id’s of the applications and to get the memory usage of the operating system and many more.
ADB:
This is used to install/uninstall/to fetch running devices/pushing or pulling files/opening shell/fetching logs/ starting or killing the adb server.
ADT:
This is a plugin for eclipse, which will be helpful in developing android applications in Eclipse.
9-patch:
This tool is used to optimize the usage of assets. This tool will add a single line pixel around the image. In which we can specify whether the corresponding pixels can be stretched or not. If we change the white space to black, then it resembles that the corresponding pixels are stretchable.
Hierarchyviewer:
This is used to view the hierarchy of the layouts in the application. Even we can download the psd’d of the screen which will provide the complete information of the screen in photoshop.
Monkeyrunner:
This is a tool for automation testing. We can specify the number of turns for testing basing on which it will test the application.
sqlite3:
This is used to check the sqllite database.