Wednesday, April 23, 2014

Android:Best practices to use default them.

Android Default Them:

Android allows you to set the appearance of your application using themes.A theme specifies default colors, fonts, and images, for an Android activity or an entire application. Your application can use the device's built-in themes, or include custom themes. By default, Titanium applications use a custom theme called Titanium for their main activity.

If you try to use an unsupported theme, you will either receive a build error that
the resource cannot be found or a runtime error that the theme is not supported.

At First, create a theme XML file in ./platform/android/res/values. Do NOT name the file theme.xml. . 
If you create a file called theme.xml, it will overwrite the default Titanium one and break the build process.
//platform/android/res/values/builtin_themes.xml
<!-- Works for Titanium SDK 3.2.x and earlier when built against Android 4.0x/API Level 14 -->
<?xml version="1.0" encoding="utf-8"?>
<resources>
      <!-- Available for Android 4.0.x/API Level 14 and later -->
      <style name="LightDarkBar" parent="@android:style/Theme.Holo.Light.DarkActionBar"/>
      <!-- Available for Android 3.0.x/API Level 11 and later -->
      <style name="Light" parent="@android:style/Theme.Holo.Light"/>
      <style name="Dark" parent="@android:style/Theme.Holo"/>
      <!-- Available for all Android versions -->
      <style name="OldLight" parent="@android:style/Theme.Light"/>
      <style name="OldDark" parent="@android:style/Theme.Black"/>
</resources>


Finally, to use a theme in your application, modify the Android section of your tiapp.xml file to reference the style name you want to use

<android xmlns:android="http://schemas.android.com/apk/res/android">
       <manifest>
             <application android:theme="@style/LightDarkBar"/>
             <uses-sdk android:minSdkVersion="14" android:targetSdkVersion="19"/>
        </manifest>
</android>

For more details:Android Theme

What do you mean by Memory leaks? And how to fix it.

Memory leaks occur when your app allocates memory but doesn't release it. Leaks occur when unintended or overlooked references to objects remain in scope. When this happens, JavaScript can't garbage collect the objects and Titanium can't destroy the native proxies. Because the causes of leaks vary so widely, at best we'll be able to give you some strategies to attempt in order to solve the problems. There are no "cookie cutter" solutions for stopping memory leaks.


The efficient tips for memory management in Titanium:

1)    Include minimum files in app.js

2)    Release objects from memory to avoid crashes and app slowness

3)    Assign objects to null instead of hiding them

4)    Remove app level events after usage

5)    Create variable using var

6)    Assign global scope to null