Wednesday, December 09, 2009

Am back...

Taking break from any habit be it daily office routine, daily food habits on anything feels good.

I took break from blogging and am back now with new enthusiasm.

Am still working on the same sms project and have learned quite a few new things on it.

Like j2me polish do not support conversion of normal canvas to blackberry canvas.

The commands does not work on it.

Also we can define structure of jar package. A new technique for optimisation namely ROMisation and much more.

On other tracks i have started given serious thought to my waistline. It is trying to break all previous records.

In same line of thoughts i have started commuting from metro.

This is my small contribution towards nature and my tummy. (seriously).

Metro has its own charm. Everyday seeing different faces, sometime same faces with different expressions. Seeing your surroundings with new outlook its all new , different and amazingly refreshing.

I now walk daily from metro drop point to my office and same way back. I really feel ported back to the time when i was in college and walking was daily routine. I feel fresh after each walk, so i will suggest to all of you that one should walk. Even five minutes of walk make tremendous changes in your outlook towards your surroundings.


One thing which am still doing and will love to do it till i can is reading.

I read the lost symbol by dan brown and was taken down by it. I found it loosely written in comparision to Da vinci code, but still a good work. He should now try his hands in different kind of writing.

I also finished the twilight series by Stephnie meyer, and if i happen to meet this lady i will like to ask her just one question. " Why do u always take the reader to extremes of emotion/adreline high and then just pushes him over the cliff".

Anyways, the new thing is i will try to update my blog daily now. Am thinking of starting a new thread here named as "What dex found today ?" .

Lets see how it evolves with time, for now , let me have my cup of clean blood :)



Monday, July 13, 2009

Memory optimisation for low end devices

So far so good. feels great to be back again.

For last few days my life was in turnmoil. Project deliveries , documentation , new project details blah blah blah.

In midst all these i got request from my client that the application was not being supported by low end devices due to memory constraints.

For those who are unaware , i had been working on a mobile application , over j2me platform , which is basically sms base servce application. It has around 50 different flows along with good UI and other flashy things in it which hogs on to memory like anything.

Now my client wants all these features to be there , and also he wants the application to work smoothly on devices with memory as low as 200KB.

So this way my journey started towards memory optimisation of the application which i myself made.

Now as you all know every developer likes his application like his own kid. So it becomes really difficult to find fault in it.

Anyways this started my voyage towards optimising my kid.

I searched web and got a lot of things and tried all of them. some helped some dint. The final outcome was that application was still throwing out of memory error on low end devices.

Then i thought lets give our code a closer look.

And that was an eye opener, there were a lot of things which needed to be done and couldnt have been possibly told by anyone.
Not going deep in to here is my own memory optimisation tips for those who want to try it out.

1. Try to seprate out all the memory allocation operations in your application

2. Check before doing any memory operation for any hogged up memories in application

3. Always make variables null if they are not intended to be use, even if they are loal variables.

4. Before doing any major memory allocation work do call system.gc(). It seems idiotic but it surely helps.

5. Dont ever do memory operations in one big chunk. sub divide memory operations in to sub modules. It helps in cleaning memroy and allocationg memory for further modules.

6. Try to use minimum number of for loops they take more memory.

7. All systems prints should be commented out before production release, they also tend to increase memory.

8. For image resources make images as png 24 and keep color combn as low as possible.

9. While deleting recordstore if you are using connection database then dont run null query, simply nullify the recordstore.

So by doing all this i got what i wanted to do.

Wednesday, April 22, 2009

Blackberry lets me down one more time :(

After my push registry incidence with blackberry , i thought that was my last mishap with blackberry and there will not be anymore just wait and see scenerio .

Yet once again the demon of blackberry has haunted me. And this time it has outdone itself.

What i was trying was to see whether i can add localisation concept in my one of the small application.

I made a phrase book which has around 25 phrases in english and i was thinking of using localisation concept and translating these 25 phrases into all readily available languages.

For my first draft i target Hindi,Herbrew,Arabic and Albanian language.

Also as i was making this project in j2me i had no issue with porting it on blackberry. Polish was there for me.
Anyways when i started developing this one lame project( initially i thought it will be one day work) , i first tried to put the translations in a txt file , and then had a hearty laugh on myself. Text file wont understand a thing about hindi as that font is not readable by it.

So , i said to myself " no issue dex, lets try the unicode thing". That is make a file in unicode format and read it that way. So when i read that file in UTF 8 format the system does not try to apply its mind and render it the way it is.

Voila it worked on my symbian device( I have one N72 and nokia 5000).

So here i thought all done in one day i can simply make a build for blackberry and give it a look.

And then my whole world of programming got cursed.

None of my UTF file worked on blackberry. My code seem to read them properly but when i displayed the contents, it was showing everythin in blocks.

Initially my guess was that blackberry was having issue in reading UTF file, but when i digged internet a bit on this issue , i came to know it was not the UTF it was the RIM who was putting curses on me one after another.

The issue here was unavailbility of different languages font.

Even if we enter any text in UTF format, to display it the device needs to have that specific font.

I dont know how but the lowest device on nokia seems to be having all the fonts which i was targetting but Blackberry dint even have the basic fonts except the languages it said it supprted which were all english based.

So here again am doomed and am thinking what can i do. I looked for UTF renderer for blackberry but found nothing. I looked for font installer and found nothing.

Am still on it but am not hoping alot . May be blackberry should start thnking in global perspective if they are hoping and are actually trying to get their devices to the masses.

Lets see what happens.

Wednesday, March 25, 2009

Push registry for sms in blackberry using midlet

I had been working around a requirement from my client and it was quite a nightmare. The codebase am working on is in j2me.
Now he wanted to port all the functionality of the code to the blackberry also.

Blackberry inherently does not executes jar/jad files. It first converts them in to cod file using its inbuilt converter RAPC and then executes them.

Now one of the functionality of my project was push registry.

The scenerio was as follows. When you start your midlet on any mobile it used to register a port for sms listening and sending . also it used to register it to AMS so that if application is not running and any sms comes on to that port then AMS can invoke my application and i will get that sms also. Till now everything was good. Everything was working fine.

I ported each and everything and it was not a big deal. But when the push registry scenerio came my world came down crashing on to me.

The code started issuing the following exception:

CLASSNOTFOUNDEXCEPTION: midlet not in current suite.

i started digging around on web for it and came to know that while registering the connection if the midlet name is not found then the following exception is thrown. Its been documented in the connector class. Also it needed the "MIDlet-1" parameter in the jad and manifest which contains the port to be registered, the name of the midlet and the filter.

So i thought may be that parameter is not passed , but when i checked in the executable it was there and was properly handled.

Now i dont know what to do.

Problem also lies in the concept of push registry . Blackberry does not have any concept called push registry, its been introduced only by j2me. So if i have to use it i have to write a midlet for blackberry. And in it , it was not working.

I searched on net all over and found so many ppl trying to work around this limitation of Blackberry but none of them have been able to.

So for whole three days i looked around and finally came to a conclusion that it cant be done in Blackberry.
We thought that we might have to shelve the blackberry from going into production as push registry was one of our key feature.

Then i got a idea . (Man am always full of ideas. )
Yesterday when i was looking for some more way arounds to solve this issue,(actually i was reading a book called "Vlad Taltos" by Steven Brust. Man am hooked onto fantasy reading , thanks to Ankit solanki. May Veera bless him. So when i finished the book ...) i thought of using a approach which no one have thought.

What if i dont ever close my application. That is when we exit from application we needed to close the port on which we were listening the sms. Now what push registry used to do was it used to keep the port status in its log. so when ever any sms came on to that port it will start the application , open and register that port again for application. But what if i never close that port?

Now issue was i have done something like this before. But i have seen that if we dont close the port and try to exit and then restart the app sometimes we will never get that port registered again.

So what i finally did was , instead of exiting the application send it into background.

what u say cheesy na :)

Blackberry has an option of sending an application in background and it can still recieve events.

so what i did was i imported the blackberry application api and sent the application in background when user wanted to exit it. Now a user thinks that app has exited but in reality its sitting in background waiting for the event . And when new sms comes on that port the application now checkes whether its in background or foreground. If foreground it does normal sms handling, but if its in background it brings the app in foreground , do a bit of initialisation and valla... we have push registry working here.

So this was my little adventure with blackberry and midlets.

May the winds of south have mercy on me.



Monday, March 23, 2009

Bulding projects using polish and porting.

For last few months i have been working on a project which has a lot of going in and around.
first of all its a mobile project. Second it targets all the leading mobile devices available around.

The language of code is so called j2me. For the porting purpose j2me polish has been used.

Now it was my first interaction with polish and for first few days or i should say months i was amazed at how polish accomplishes such a tedious task.

Being in to mobile industry for quite some time i know how tedious and complex is the task of supporting n number of devices which have all together different property set.

The properties are not just the screen size or the api sets , but also the underlying OS capabilities, changes in the same OS as there are always some feature packs available. Key pad mapping, UI capabilities mapping, Use of restricted apis and blab blah blah.

It was always a nightmare for me when i had to port any of my application onto all target devices.
But polish seems to do it quite painlessly.

So i thought why not give polish a close look and see how it does that.

what i found out was quite straight and simple.
Polish with the help of ant takes control of complete building process of any j2me application.

The polish people have written their own routines and code fragments which overrides the default building process. Along with that they have also used the brute force.

What i mean by brute force is they have indexed all the important and not so important capabilities and features of mobile and have made a standard around it. Now whenever you are building a build for any device, its capabilities are hand written in one of the files given by polish people.

this file is called devices.xml. This xml has got indexed features of n number of mobile devices and its ever growing. We can add our own blocks also in it.

Now this all seems to good , but at the end what i found out was it all is on good faith. As its open to changes by anyone, anybody can play around with it. Its very easy to change the name of any device or its feature.

Also i found porting to different devices buggy.

The code am working on has to work on blackberry also. Now during the build process itself the polish issues warning like error in jdptask and utiltask. Even if you build its demo project for blackberry you get the same issue. The web is full of issues faced by developers while porting on different devices.

Some how i fixed the jdp error in the polish jar and when i run the blackberry cod on the device it gives refrence member out of range error. Now its something which cannot be resolved by a developer. am still stuck on it and finally have decided to re write the whole code in blackberry ide itself and build blackberry native code.

So for small portings and portings on normal devices polish is good, but for other devices and for complex projects play with it at your own risk. :)

follow me