core data is not thread safe

iOS/Cocoa : Resolving deadlock caused by core data multi threading

Recently when I was doing some performance fixes for an iOS app I am working on, I came across a strange issue.  The app UI would freeze indefinitely without causing a crash or hitting a breakpoint. This freeze was intermittent, which made things difficult. Initially I suspected a deadlock in some new code, but I had not introduced any explicit @synchronized or semaphore wait statements in the code <which generally cause deadlocks>. All I had done is moved JSON response parsing code to a shared background queue.

On the debugger, hitting the pause button showed me that the execution was stuck in [pmutex wait] method. Quick googling of this gave me the answer I was looking for.

core data is not thread safe

core data is not thread safe !

Cause

What had happened was that I was using Core Data abstraction for database storage and I had made a singleton class for all database methods (seems like a bad idea now). Continue reading “iOS/Cocoa : Resolving deadlock caused by core data multi threading” »

Screen Shot 2013-03-24 at 1.33.59 AM

Will Nexus 4 work well in India ? FAQ for Indian owners of LG Nexus 4

UPDATE (16th May, 2013) : Nexus 4 is now officially available in India for 25999Rs

Airtel Nexus 4

Are you thinking of buying a Nexus 4, but are skeptical whether it works well in India ? Are you worried that you can use your existing sim card like Airtel/Vodafone with your new phone ? Are you scared that you wont be able to download India-only apps on the play store ?

Then this blog post is for you. This will help you decide whether it is safe to import nexus 4 from outside India.

If you want to buy a nexus 4, read my article on how to buy nexus 4 in india.

Does Nexus 4 work well on Indian SIM cards ?

Yes it does.

 

See the screenshot below which shows Nexus 4 running on Airtel prepaid sim.

 

But the only catch is that it Continue reading “Will Nexus 4 work well in India ? FAQ for Indian owners of LG Nexus 4” »

Account Preferences | MyUS.com

Buy LG Nexus 4 in India for 21,500 Rs.

UPDATE (16th May, 2013) : Nexus 4 is now officially available in India for 25999Rs

Here’s a story of how I managed to get my brand new LG nexus 4 phone in India for just 21500 INR.

Nexus 4 india price

Are you one of those people who are impatient enough to wait for nexus 4 to arrive in India? I was , and this is how I managed to get Nexus 4 in Bangalore for a cheap price. The price is so cheap that even if I sell my used iPhone 4, I would be in profit.

The order

Nexus 4 stock is available in US Google play store. But the catch is that when you try to access it from a non US IP address, this is what you get  :

Sorry! Devices on Google Play is not available in your country yet.
We’re working to bring devices to more countries as quickly as possible.
Please check back again soon.

What I then tried was to use a SOCKS proxy from http://www.hidemyass.com/proxy-list/.

But when I tried using a proxy, google detected it and Continue reading “Buy LG Nexus 4 in India for 21,500 Rs.” »

nexusae0_Screenshot_2013-02-12-11-47-41

How to fix adb “device offline” issue after android 4.2.2 upgrade

After I upgraded my nexus 4 to 4.2.2 I noticed that my adb stopped working (Mac). I quickly googled for the issue and I saw that many people are facing the same problem. But none of the solutions specified worked for me. After spending a lot of time trying to fix it, I finally managed to figure it out. I had almost decided to load a custom rom to make adb work, but thankfully it worked without that.

<Assuming you are running these commands in Mac/Linux>

  1. Goto your android sdk dir > platform-tools , and then run ./adb devices. It should show your device as offline. Only if this is the case, proceed with the next set of steps
  2. Run ./adb version
    Android Debug Bridge version 1.0.31. If it does not show this, you might need to upgrade your adb. In my case it did show the right version, but even then adb devices shows my device as offline.
  3. Next, try ./adb kill-server and then Continue reading “How to fix adb “device offline” issue after android 4.2.2 upgrade” »
ICS-developerTools

Android contexts and singletons

google android context and singleton class and application relaunchUnderstanding contexts in android correctly is every developers nightmare. This article highlights some of the findings which will help you understand contexts in android a little better. This article is more useful if you follow a singleton pattern in your app.

The general rule of thumb when using contexts is to use the activity’s context whenever possible. I would like to highlight some of the issues when I followed this rule blindly without understanding contexts correctly. In one of the projects, a lot of singleton classes were used to maintain states of different components used throughout the app. For e.g, DatabaseManager was a singleton which was a single point of entry to perform all the DB operations. Now, there are lot of developers who hate using singletons in java, because it gets abused quite a lot and make is difficult to reuse/separate components if required. Read this for more info.

Anyways, we ended up using a singleton pattern throughout our app. But some of the singletons required to use the android context for initialization. So the first thing which came to our mind was to initialize these singletons on app startup.

Mistake 1

The first mistake we did was we used Continue reading “Android contexts and singletons” »