Android工作室的入职屏幕

问题描述 投票:2回答:1

我正在尝试构建一个OnboardingActivity并且我已经实现了它但是现在我希望它应该对新用户可见或者每个用户一次,我尝试共享首选项但是没有效果。我使用Splash Screen作为Launcher Activity和MainActivty&onboardingActivity作为下一个意图。

SplashActivity

import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;

import android.content.Intent;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.WindowManager;

public class SplashActivity extends AppCompatActivity {


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_splash);
    getSupportActionBar().hide();


    Thread myThread = new Thread() {
        @Override
        public void run() {
            try {
                sleep(3000);
                Intent intent = new Intent(getApplicationContext(), OnBoardActivity.class);
                startActivity(intent);
                finish();

            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    };
    myThread.start();
}
}

OnBoardActivity

import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.os.Bundle;


import com.hololo.tutorial.library.Step;
import com.hololo.tutorial.library.TutorialActivity;


public class OnBoardActivity  extends TutorialActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
 SharedPreferences preferences =  getSharedPreferences("my_preferences", 
 MODE_PRIVATE);

 // Check if onboarding_complete is false 
 if(!preferences.getBoolean("onboarding_complete",false)) {
// Start the onboarding Activity
Intent onboarding = new Intent(this, OnBoardActivity.class);
startActivity(onboarding);

// Close the main Activity
finish();
return;
}

//slide1
    addFragment(new Step.Builder().setTitle("WELCOME.NAMASTE!!")
            .setSummary("It seems like you are a New User!!\nWe welcome you 
to GFeed.")
            .setBackgroundColor(Color.parseColor("#FFA600")) // int 
background color
            .setDrawable(R.drawable.gh) // int top drawable

            .build());
    //slide2
    addFragment(new Step.Builder().setTitle("CAREER ORIENTED")
            .setSummary("This app includes some awesome career oriented 
    elements such as Internship,different courses related to CS/IT,career 
   tips by experts.")
            .setBackgroundColor(Color.parseColor("#FFA600")) // int 
   background color
            .setDrawable(R.drawable.human) // int top drawable

            .build());
    //slide3
    addFragment(new Step.Builder().setTitle("COLLEGE ORIENTED")
            .setSummary("This app includes some awesome college oriented 
    elements such as college club news,aktu feed,H.O.D'corner and Gsim")
            .setBackgroundColor(Color.parseColor("#FFA600")) // int 
    background color
            .setDrawable(R.drawable.college) // int top drawable

            .build());
   }

  @Override
 public void finishTutorial() {

  SharedPreferences preferences =
        getSharedPreferences("my_preferences", MODE_PRIVATE);

 // Set onboarding_complete to true
 preferences.edit()
        .putBoolean("onboarding_complete",true).apply();

 // Launch the main Activity, called MainActivity
 Intent main = new Intent(this, MainActivity.class);
 startActivity(main);

 // Close the OnboardingActivity
 finish();
   }
 }

清单文件

<uses-permission android:name="android.permission.INTERNET" />

<application
    android:allowBackup="true"
    android:icon="@drawable/vtry"
    android:label="@string/app_name"
    android:largeHeap="true"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity
        android:name=".SplashActivity"
        android:screenOrientation="portrait">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name=".MainActivity"
        android:label="@string/app_name"
        android:screenOrientation="portrait"
        android:theme="@style/AppTheme.NoActionBar">
        <intent-filter>
            <action android:name="MAINACTIVITY" />

            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>
    <activity android:name=".developer"
        android:screenOrientation="portrait">
    </activity>
    <activity android:name=".notify"
        android:screenOrientation="portrait">
        <intent-filter>
            <action android:name="NOTIFY" />

            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>
    <activity android:name=".download"
        android:screenOrientation="portrait">
    </activity>
    <activity android:name=".webvr"
        android:screenOrientation="portrait">
        />
        <intent-filter>
            <action android:name="WEBVR" />

            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>
    <activity android:name=".gsim"
        android:screenOrientation="portrait">
        />
    </activity>
    <activity android:name=".Internship"
        android:screenOrientation="portrait">
       />
    </activity>
    <activity android:name=".Courses"
        android:screenOrientation="portrait">
       />
    </activity>
    <activity android:name=".Aktu"
        android:screenOrientation="portrait">
        />
    </activity>
    <activity android:name=".Interview"
        android:screenOrientation="portrait">
    </activity>
    <activity android:name=".Reachus"
        android:screenOrientation="portrait">
    </activity>
    <activity android:name=".OnBoardActivity"
        android:screenOrientation="portrait">

    </activity>
    <service
        android:name=".FirebaseMessagingService">
        <intent-filter>
            <action android:name="com.google.firebase.MESSAGING_EVENT"/>


        </intent-filter>
    </service>
    <!-- Set custom default icon. This is used when no icon is set for incoming notification messages.

    <meta-data
        android:name="com.google.firebase.messaging.default_notification_icon"
        android:resource="@drawable/vtry" />
    <!-- Set color used with incoming notification messages. This is used when no color is set for the incoming

    <meta-data
        android:name="com.google.firebase.messaging.default_notification_color"
        android:resource="@color/colorAccent" />

</application>
java android android-layout android-studio-2.3
1个回答
1
投票

OnboardActivity中,您正在检查入职是否未完成以开始相同的活动。 逻辑应该是反向的,检查入职是否完成并启动MainActivity

if(preferences.getBoolean("onboarding_complete",false)) {
    // Start Main Activity
    Intent intent = new Intent(this, MainActivity.class);
    startActivity(intent);

    // Close Onboarding
    finish();
    return;
}

因此,如果入职未完成,您将继续参加同一活动。 还要检查是否正在调用方法finishTutorial

© www.soinside.com 2019 - 2024. All rights reserved.