Delete all cached file after uninstall Android app


When running app, app will create a lot of cached files. If user uninstall app, I think that these files need to be removed. I suggest a solution for this issue:

  • Write cached file to External Cached Directory
  • If the user uninstalls your application, these files will be automatically deleted.


How to implement

You can also access a cache directory on a secondary external storage (if available) by calling ContextCompat.getExternalCacheDirs()

Integrating Google photo to Android application


Picasa – Google photo is a fast and easy sharing photo from Google. We can access Google photo album by integrating Android application.

Our steps:

  • Ask user to pick a google account
  • When we get the account back, ask for access to the picasa picture
  • Then we get our token
  • Get albums and images from picasa by our token

How to integrating

  1. Adding libraries by gradle
    compile ''
    compile group: '', name: 'core', version: '1.47.1'
  2. Ask user to pick a google account
    Intent googlePicker = AccountPicker.newChooseAccountIntent(null, null, new String[]{GoogleAuthUtil.GOOGLE_ACCOUNT_TYPE}, true, null, null, null, null);
    super.startActivityForResult(googlePicker, Config.PICK_PICASA_ALBUM);
  3. Get token
    public void onActivityResult(int requestCode, int result, Intent data) {
        if (result == RESULT_OK && requestCode == Config.PICK_PICASA_ALBUM) {
            super.onActivityResult(requestCode, result, data);
   = data.getStringExtra(AccountManager.KEY_ACCOUNT_NAME);
            this.type = data.getStringExtra(AccountManager.KEY_ACCOUNT_TYPE);
    private void getTokenOfPicasa() {
        Account account = new Account(, this.type);
        AccountManager accountManager = AccountManager.get(this);
        accountManager.getAuthToken(account, "lh2", null, this,
            new AccountManagerCallback<Bundle>() {
                public void run(AccountManagerFuture<Bundle> result) {
                    try {
                        Bundle bundle = result.getResult();
                        if (bundle.containsKey(AccountManager.KEY_AUTHTOKEN)) {
                            authToken = bundle.getString(AccountManager.KEY_AUTHTOKEN);
                            new GetAlbumsOfPicasa().execute();
                    } catch (Exception e) {
                            Log.e(TAG, "getTokenOfPicasa", e);
        }, null);
  4. Get albums and images
    private class GetAlbumsOfPicasa extends AsyncTask<Void, Void, Void> {
        private List<Album> albums;
        protected Void doInBackground(Void... params) {
            // Get albums and images of Picasa
            getAlbumsOfPicasa(email, authToken);
            return null;
        protected void onPostExecute(Void aVoid) {
    public List<AlbumEntry> getAlbumsOfPicasa(String email, String authToken) {
        try {
            String API_PREFIX = "";
            PicasawebService picasaService = new PicasawebService("pictureframe");
            String albumUrl = API_PREFIX + email;
            UserFeed userFeed = picasaService.getFeed(new URL(albumUrl), UserFeed.class);
            List<GphotoEntry> entries = userFeed.getEntries();
            List<AlbumEntry> albums = new ArrayList<>();
            for (GphotoEntry entry : entries) {
                AlbumEntry albumEntry = new AlbumEntry(entry);
            return albums;
        } catch (Exception e) {
            Log.e(TAG, "getAlbumsOfPicasa", e);
            return null;

OnTextChanged with ButterKnife

XML file


Java file

protected void onTextChanged(CharSequence text) {
    String featureName = text.toString();
    Log.i(TAG, "feature name:" + featureName);

Building Apps with Over 65K Methods


As the Android platform has continued to grow, so has the size of Android apps. When your application and the libraries it references reach a certain size, you encounter build errors that indicate your app has reached a limit of the Android app build architecture. Earlier versions of the build system report this error as follows:

Conversion to Dalvik format failed:
Unable to execute dex: method ID not in [0, 0xffff]: 65536

Both these error conditions display a common number: 65,536. This number is significant in that it represents the total number of references that can be invoked by the code within a single Dalvik Executable (dex) bytecode file. If you have built an Android app and received this error, then congratulations, you have a lot of code! This document explains how to move past this limitation and continue building your app.

About the 65K Reference Limit

Android application (APK) files contain executable bytecode files in the form of Dalvik Executable (DEX) files, which contain the compiled code used to run your app. The Dalvik Executable specification limits the total number of methods that can be referenced within a single DEX file to 65,536, including Android framework methods, library methods, and methods in your own code. Getting past this limit requires that you configure your app build process to generate more than one DEX file, known as a multidex configuration.

How to implement

    • Import to build.gradle

      android {
          compileSdkVersion 21
          buildToolsVersion "21.1.0"
          defaultConfig {
              minSdkVersion 14
              targetSdkVersion 21
              // Enabling multidex support.
              multiDexEnabled true
      dependencies {
        compile ''

    • Create application file
public class SimplePrintsApp extends MultiDexApplication
    protected void attachBaseContext(Context base) {
    • Import to AndroidManifest.xml

In conclusion

This above solution will help us to create application that has many libraries and method.

Simple Splash screen on Android


Splash screen is the first screen of application. It often shows your logo, slogan  in a few seconds. I will introduce a simple way to implement Splash screen on Android application

1418337663850-2014-12-11 15.16.39

How to implement


public class SplashActivity extends BaseActivity {
    private static final String TAG = SplashActivity.class.getSimpleName();

    private static final int TIME_TO_DISPLAY_SPLASH_SCREEN = 3000;

    protected void onCreate(Bundle savedInstanceState) {

    private void launchGreenFood() {
        Handler handler = new Handler();
        handler.postDelayed(new Runnable() {
            public void run() {

    private void goToMainScreen() {
        Intent intent = new Intent(this, MainActivity.class);

Add activity_splash.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android=""


Declare SplashActivity  in manifest

                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>

In summary

This solution is easy way to implement Splash screen. You can add business login in SplashActivity such as: load database, init app, load data from server.

Install Genymotion for testing app


Genymotion is a system that provide many Android virtual devices for testing. Genymotion is 100% compliant with Android APIs because we follow exactly the same rules as every Android device factory.

You can research about Genymotion in this link

How to install

To install Genymotion, follow the steps corresponding to your operating system.