Intent跳轉工具類

Intent跳轉工具類

可進行快速的參數傳遞並跳轉,還有跳轉動畫

import java.io.Serializable;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
public class IntentHelper {

    private IntentHelper util;

    public IntentHelper getInstance() {

        if (util == null) {
            util = new IntentHelper();

        }
        return util;

    }

    private IntentHelper() {
        super();
    }

    /**
     * 頁面跳轉
     * 
     * @param context
     * @param c
     */
    public  void showIntent(final Context context, final Class c) {
        showIntent(context, c, null, null);
    }

    /**
     * 傳數據的頁面跳轉
     * 
     * @param context
     * @param c
     * @param keys
     * @param values
     */
    public  void showIntent(final Context context, final Class c,
            String[] keys, Serializable[] values) {
        Intent intent = new Intent();
        intent.setClass(context, c);
        if (null != keys) {
            int i = 0;
            for (String key : keys) {
                intent.putExtra(key, values[i]);
                i++;
            }
        }

        context.startActivity(intent);
//      跳轉動畫
         context.overridePendingTransition(
         R.anim.appear_top_left_in,
         R.anim.disappear_bottom_right_out);

    }
    public  void showIntentForResult(final Activity context, final Class c,
            String[] keys, Serializable[] values,int result) {
        Intent intent = new Intent();
        intent.setClass(context, c);
        if (null != keys) {
            int i = 0;
            for (String key : keys) {
                intent.putExtra(key, values[i]);
                i++;
            }
        }

        context.startActivityForResult(intent, result);

         context.overridePendingTransition(
         R.anim.appear_top_left_in,
         R.anim.disappear_bottom_right_out);

    }


    /**
     * 用動畫效果的頁面關閉
     * 
     * @param activity
     */
    public  void finish(Activity activity) {
        activity.finish();
         activity.overridePendingTransition(R.anim.appear_bottom_right_in,
         R.anim.disappear_top_left_out);

    }
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章