Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import android.app.Activity;

import android.os.Handler;

import android.widget.Toast;

public class Main {
    /**
     * Function use through the app to show Toast information and finish current activity.
     * Function is called so often from background, that it's content is explicitly called from UIThread.
     *
     * @param activity         - is current activity to finish
     * @param stringResourceId of text we show
     * @param handler          to UIThread
     */
    public static void showToastAndFinishActivity(final Activity activity, final int stringResourceId,
            Handler handler) {
        handler.post(new Runnable() {
            @Override
            public void run() {
                Toast.makeText(activity, activity.getString(stringResourceId), Toast.LENGTH_SHORT).show();
                activity.finish();
            }
        });
    }
}