Skip to Content

About: admin

Recent Posts by admin

Android studio hangs “Waiting for ADB”

I have been getting android studio hangs intermittently (whole window frozen) and it looks to just be ADB hanging. Seems to happen a lot when my mac sleeps. The solution was just to restart adb using : adb kill-server; adb start-server Hopefully this will be fixed soon. the whole Android studio inferface shouldn’t hang just because ADB isn’t responding – it should be in a background task. Hope it helps someone.

Recover files from a non booting device

This is for when you have not been able to boot your phone and need to get files off it. The device (a Nexus 4) turns on but never makes it past the loading screen. So it doesn’t finish booting – but mine had booted enough to have ADB running. To use this method you need to have ADB installed on the host. (e.g. install dev tools – see [1]) * To get the list we use ADB shell $ adb shell shell@mako:/ $ ls /sdcard/ … DCIM/ shell@mako:/ $ ls /sdcard/DCIM/ 100ANDRO/ Camera/ shell@mako:/ $ ls /sdcard/DCIM/Camera/ … (list files) * Take this list (select+copy) and paste to to a local file say picnames.txt * Then execute $ cat picnames.txt | xargs -I % adb pull /sdcard/DCIM/Camera/% 7003 KB/s (3677132 bytes in 0.512s) … This should copy the files to the local directory … phew! refs: [1] http://developer.android.com/sdk/index.html

Some great in depth turtorials and slide for Android tasks

These are some great tutorial/slides I found recently: Threading: http://www.slideshare.net/andersgoransson/efficient-android-threading Loaders: http://www.slideshare.net/cbeyls/android-loaders-reloaded Android source: Android Source Code Guided Tour from Kevin McDonagh

Setting up Junit ServiceTestUnit tests with Application references

I have been setting up unit testing for an existing project of late and when testing services I ran into problems setting up the application and base context references. Searching around – I wasn’t able to find a way to do this, hence I am noting it down to make it (hopefully) easier for you.. Setting the Application context in the test unit setUp() enabled me to get the Application object but many other calls did not work (e.g. getPackageName()). To properly setup the application object we need to set the Base Context for the application object. This can be done by overriding attachBaseContext(Context base) in the application object and making it public. Of course you shouldn’t really have to change your source to run tests – but in practice it happens anyways (e.g. making methods public to call them from the test). Application This method is added to the application object it overrides the default from ContextWrapper @Override public void attachBaseContext(Context base) { super.attachBaseContext(base); } DownloadServiceTest public class DownloadServiceTest extends ServiceTestCase<DownloadService> { DownloadService _downloadService; public DownloadServiceTest() { super(DownloadService.class); } public DownloadServiceTest(Class<DownloadService> activityClass) { super(activityClass); } protected void setUp() throws Exception { super.setUp(); MyPODApplication myPODApplication = new MyPODApplication();// the application object // the overrided method to attach the context – we pass the Context provided by getSystemContext(); myPODApplication.attachBaseContext(getSystemContext()); setApplication(myPODApplication); getApplication().onCreate(); setContext(getApplication()); Intent i = new Intent(getSystemContext(),DownloadService.class); i.setAction(Globals.INTENT_START_DOWNLOADS); Log.d(DownloadService.class.getSimpleName(), “dl svc started”); startService(i); // should use a service binder here _downloadService = getService(); } // more test methods here }

Using CSS precedence

I have been coming back to HTML / CSS lately and I came across errors where my CSS would not be overridden. Then I found this very good article on CSS Precedence by Steven Bradley. http://www.vanseodesign.com/css/css-specificity-inheritance-cascaade/ This article gives a thorough understanding of CSS Precedence, and is well considered looking at the comments … The thing I got from it was that it is probably better to design your HTML with pseudo tags, as those styles will always give the lowest precedence. Then base styles can then be overridden more easily by giving class (0 0 1 0) or id (0 1 0 0) attributes to elements. This should give the greatest flexibility in correcting errors, and creating re-useable CSS. Using !important should not be necessary in well designed CSS. They can be handy in a quick spot I guess – but long term they just make the CSS harder to edit. W3 ref: http://www.w3.org/TR/CSS2/cascade.html

Recent Comments by admin

    No comments by admin yet.