Tuesday, December 15, 2015

Google AppEngine : From Eclipse to Android Studio

So recently I decided to take another look at Android Studio and migrate my most involved App (Follow Chess). Follow Chess uses several "shared libraries" and ofcourse the connected AppEngine project.

In this post I will only talk of the two most important things which were required for me to migrate the Eclipse App Engine project to Android Studio. (its assumed that the App engine project has already been added to Android Studio as "module")

No Class def found errors
Its important to have the correct libraries. In my case, the following were missing and had to be added to the module's build.gradle; in addition to the usual suspects:

compile 'org.ow2.asm:asm:4.0'compile 'org.apache.geronimo.specs:geronimo-jpa_2.0_spec:1.0'compile 'org.datanucleus:datanucleus-api-jpa:3.1.3'

persistence.xml

The persistence.xml file should be copied over to <module>/src/main/resources/META-INF/ directory. By default the resources folder did not exist, so I had to create one.
If this is not done and the xml is not available to the project, then at the run-time, there would be errors in Server logs (complaining that persistence.xml could not be found)

Enhance classes
The entity classes need to be enhanced. If this is not done, then you would usually see errors in server logs:
MetaDataManager initialiseFileMetaDataForUse: Found Meta-Data for class xxxxxxxxx but this class is not enhanced!! Please enhance the class before running DataNucleus.

For this, I had to add the following to my module's build.gradle file:

enhancer {
    version = "v2"    api="jpa"    enhanceOnBuild = true}

Wednesday, October 24, 2012

How to stop Android Monkey UI exerciser

Started monkey test but wish to stop it now?
Find the process with a question mark as shown above. That is most likely the monkey process.
Just kill it!

Saturday, January 28, 2012

Keep Screen On!

Sometimes you just want to keep the screen light on while the user is on a certain Activity.
Enter.. FLAG_KEEP_SCREEN_ON!

FLAG_KEEP_SCREEN_ON - "Window flag: as long as this window is visible to the user, keep the device's screen turned on and bright. "



Usage: 
A. Inside the onCreate() method of your Activity
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

or

B. In your layout xml
<RelativeLayout... android:keepScreenOn="true" />

As long as this Activity is shown to the user, the screen light will be on! Once the user moves over to another activity, the default screen timeout will kick-in.
No wake lock required!

Friday, November 4, 2011

Easy way to install an apk on Windows

If you are a developer, you would frequently generate an apk on a remote machine and copy to your Windows PC and then install it on your phone. Or an apk sent by your team member.
Here is a quick and convenient way to install the apk on your phone with a double-click!

1. Copy the below code to a text file, and rename it install_apk.bat. Save the .bat file somewhere on PC
adb install -r %1
PAUSE

(if you adb.exe is not on classpath, you can also specify the complete path to the exe. Ex C:\android-sdk-windows\platform-tools\adb.exe)

2. In windows explorer, select your apk -> Right click -> Open With -> Choose Program -> Browse -> Select the above .bat file
Also, check "Always use selected program..." option.
Click OK

Thats it, now you can install any apk with a double click (provided a device is connected to the PC via usb)

The Simplest List View!


Android has a built-in layout android.R.layout.simple_list_item_1

But how do you really take advantage of this, without creating a separate XML of your own?

Here is how I did it...

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
       
        List<String> data = new ArrayList<String>();
        data.add("King");
        data.add("Queen");
        data.add("Bishop");
        data.add("Rook");
       
        ArrayAdapter arrayAdapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1, data );
        setListAdapter(arrayAdapter);
       
        getListView().setOnItemClickListener(new AdapterView.OnItemClickListener() {

            public void onItemClick(AdapterView<?> parent, View view, int position,
                    long arg3) {
                //item clicked
            }
        });
    }




---------------------
No setContentView, no separate XML required!


Thats all!! Trust me.