每次启动应用程序时启动活动

时间:2016-08-26 17:11:44

标签: android android-activity sharedpreferences

我的应用会打开"011111111",但实际上我想在应用启动时打开MainActivity。我尝试了一些解决方案,如:

LoginActivity

    PackageInfo info = null;
    try {
        info = getPackageManager().getPackageInfo(PACKAGE_NAME, 0);
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
    }

    int currentVersion = info.versionCode;
    this.versionName = info.versionName;
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    int lastVersion = prefs.getInt("version_code", 0);
    if (currentVersion > lastVersion) {
        prefs.edit().putInt("version_code", currentVersion).apply();
        startActivity(new Intent(ScheduleActivity.this, LoginActivity.class));
    }

1 个答案:

答案 0 :(得分:3)

在您的清单文件中设置您的活动,例如:

<?php

namespace App\Http\Controllers;

class SchedulersController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        //
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        //
    }
}