Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
/**
 Copyright (C) 2010 Forrest Guice
 This file is part of Thunder-Stopwatch.
    
 Thunder-Stopwatch is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 (at your option) any later version.
    
 Thunder-Stopwatch is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
    
 You should have received a copy of the GNU General Public License
 along with Thunder-Stopwatch.  If not, see <http://www.gnu.org/licenses/>.
 */

import android.content.Context;
import android.content.Intent;

public class Main {
    public static Intent createIntent(Context context, Class<?> classObj) {
        Class<?> activityClass = getActivityClass(context, classObj);
        return new Intent(context, activityClass);
    }

    private static Class<?> getActivityClass(Context context, Class<?> classObj) {
        StringBuilder b = new StringBuilder(255);
        b.append(context.getPackageName());
        b.append(".");
        b.append(classObj.getSimpleName());
        b.append("Ext");

        String extClassName = b.toString();
        try {
            Class<?> extClass = Class.forName(extClassName);
            return extClass;

        } catch (ClassNotFoundException e) {
            //e.printStackTrace();   // DEBUG: uncomment to debug
            return classObj;
        }
    }
}