Recent Posts

Showing posts with label Android. Show all posts
Showing posts with label Android. Show all posts

Android: Unfortunately MyApp has stoped

The Problem Your application quit because an uncaught RuntimeException was thrown. The most common of these is the NullPointerException. How to solve it? Every time an Android application crashes (or any Java application for that matter), a Stack trace is written to the console (in this case, logcat). This...

Android: How to get screen width and height

If you want the display dimensions in pixels you can use getSize: Display display = getWindowManager().getDefaultDisplay(); Point size = new Point(); display.getSize(size); int width = size.x; int height = size.y; If you're not in an Activity you can get the default Display via WINDOW_SERVICE: WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); Display display = wm.getDefaultDisplay(); Before...

Android SDK installation doesn't find Java JDK

In order to fix this press Back when you get the notification and then Next. This time it will find the J...

Proper use case for Android UserManager.isUserAGoat()

In the Android 4.2 API there's the UserManager class and the method: public boolean isUserAGoat () From their source, it looks like the method returns false all the time:/** * Used to determine whether the user making this call is subject to * teleportations. * @return whether the user making this call is a goat */ public boolean isUserAGoat() { return false; } It looks like the method has no real use for...

Hide or close the Android Soft Keyboard

If you have in your layout a EditText and want to hide it with a Button then you can force Android to hide the virtual keyboard using the InputMethodManager, calling hideSoftInputFromWindow, passing in the token of the window containing your edit field. EditText myEditText = (EditText) findViewById(R.id.myEditText); InputMethodManager imm = (InputMethodManager)getSystemService( Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(myEditText.getWindowToken(),...

Android: "Debug certificate expired" Eclipse Plugins error

In order to fix the Debug certificate expired delete your debug certificate under ~/.android/debug.keystore on Linux and Mac OS X; the directory is something like %USERPROFILE%/.android on Windows. The Eclipse plugin should then generate a new certificate when you next try to build a debug package. You may need to clean and then build to generate the certifica...

How to: save activity state in Android App

I've been playing around with the Android SDK, and I am a little unclear on saving an application's state. So given this minor re-tooling of the 'Hello, Android' example: package com.android.hello; import android.app.Activity; import android.os.Bundle; import android.widget.TextView; public class HelloAndroid extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle...

How do a lazzy load of images in ListView

This code hold the images package com.wilson.android.library; /* Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You...