如何将应用程序部署到设备后,开始另一个活动为主要和发射器 [英] How to start another Activity as main and launcher after Deploying the application into device

查看:109
本文介绍了如何将应用程序部署到设备后,开始另一个活动为主要和发射器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发的应用程序。 我的要求是,当我安装到设备有启动主发射活动​​的应用程序第一次。    之后,当我开始/打开我的应用程序端的装置它必须加载另一个活动,而不是主启动程序。    如果应用程序的卸载和重新安装它必须加载主和发射一次。 可以请你分享人对这种主题的解决方案。

I am developing an application. my requirement is that first time when i installing the application in to device it has to start the main and launcher activity. After that when i am starting/opening my application in side the device it has to load another activity instead of main and launcher. If the application is uninstalls and installs again it has to load the main and launcher again. can you please anybody share the solution on this kind of topics.

在此先感谢。

推荐答案

你可以这样做:

说活动A是要推出仅在第一次活动,和b活动,该系统将在第一时间后启动的活动。

Say Activity A is the activity that you want to launch only the first time, and activity B the activity that the system will launch after the first time.

在你舱单,把b活动作为你的发射活动。然后活动的OnCreate或更好OnResume内b将以下内容:

In you manifest put Activity B as your launcher activity. Then inside the oncreate or better OnResume of activity B put the following:

    @Override
protected void onResume() {
    super.onResume();

       if(firstLaunch()){
           startActivity(new Intent(this, A.class));
           finish();
       }else{
         //Do your normal stuff
       }

    }


    private boolean firstLaunch(){
         SharedPreferences prefs = getSharedPreferences(
            "Preferences",
            Context.MODE_PRIVATE);
         return prefs.getBoolean("firstLaunch",false);
    }

然后在你的一个活动,一定要在你的preferences设置一个标志,表明您的应用程序已经运行超过一次。所以某处活性的把这样的:

Then on your A activity be sure to set a flag on your preferences to indicate that your application has run more than once. So somewhere inside activity A put this:

   private void setFirsLaunchFlag(){
         SharedPreferences prefs = getSharedPreferences(
            "Preferences",
            Context.MODE_PRIVATE);
         SharedPreferences.Editor edit = prefs.edit();
         edit.putBoolean("firstLaunch",true);
         edit.commit();
   }

这篇关于如何将应用程序部署到设备后,开始另一个活动为主要和发射器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆