Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.io.FileOutputStream;

import android.app.Activity;
import android.content.Intent;
import android.widget.Toast;

public class Main {
    final static String FILENAME = "last_activity.txt";

    public static void startActivity(Activity current, Class<? extends Activity> next) {
        saveActivity(current, next);
        Intent i = new Intent(current, next);
        current.startActivity(i);
        current.finish();
    }

    private static void saveActivity(Activity activity, Class<? extends Activity> clazz) {
        FileOutputStream fos = null;
        try {
            fos = activity.openFileOutput(FILENAME, Activity.MODE_PRIVATE);
            fos.write(clazz.getName().getBytes());
        } catch (Exception e) {
            Toast.makeText(activity, "saveActivity: " + e, Toast.LENGTH_LONG).show();
        } finally {
            if (null != fos)
                try {
                    fos.close();
                } catch (Exception e) {
                }
        }
    }
}