Reputation: 131
I've been at it for hours now... please can anyone point out the issue here?
this is my values/styles:
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
<style name="AppTheme.NoActionBar">
<item name="android:windowDisablePreview">true</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="Theme.Transparent" parent="AppTheme">
<item name="android:windowDisablePreview">true</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowActionBar">false</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowIsTranslucent">true</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
</resources>
this is my manifest file:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.nuku.mc.myfypapp">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/Theme.Transparent">
<activity
android:name=".SplashScreen"
android:theme="@style/Theme.Transparent"
android:label="@string/app_name"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".LoginActivity"
android:label="@string/app_name"
android:windowSoftInputMode="adjustPan"
/>
<activity
android:name=".SignupActivity"
android:windowSoftInputMode="adjustPan" />
<activity
android:name=".MainActivity"
android:launchMode="singleTop"
android:label="@string/app_name"
android:windowSoftInputMode="adjustPan" />
</application>
</manifest>
this is the app splash_screen.xml file
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/lin_lay"
android:background="@android:color/holo_orange_dark">
<ImageView
android:layout_width="360dp"
android:layout_height="480dp"
android:id="@+id/imageView2"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:background="@android:color/holo_orange_dark"
android:contentDescription="@string/splash_text"
/>
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="@string/splash_text"
android:id="@+id/splashText"
android:layout_marginBottom="150dp"
android:layout_alignBottom="@+id/imageView2"
android:layout_centerHorizontal="true"
android:textStyle="bold|italic"
android:focusable="true"
android:textSize="@dimen/design_fab_image_size"
android:textColor="#ffffff" />
</RelativeLayout>
this is splash.java
public class SplashScreen extends Activity {
SessionManager manager;
public void onAttachedToWindow() {
super.onAttachedToWindow();
Window window = getWindow();
window.setFormat(PixelFormat.RGBA_8888);
}
@Override
public void onCreate(Bundle savedInstanceState, PersistableBundle persistentState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash_screen);
manager = new SessionManager();
StartAnimations();
}
private void StartAnimations() {
Animation anim = AnimationUtils.loadAnimation(this, R.anim.alpha);
anim.reset();
RelativeLayout l=(RelativeLayout) findViewById(R.id.lin_lay);
l.clearAnimation();
l.startAnimation(anim);
anim = AnimationUtils.loadAnimation(this, R.anim.translate);
anim.reset();
ImageView iv = (ImageView) findViewById(R.id.imageView);
iv.clearAnimation();
iv.startAnimation(anim);
Thread background = new Thread() {
public void run() {
try {
// Thread will sleep for 3 seconds
sleep(3*1000);
// After 5 seconds redirect to another intent
String status=manager.getPreferences(SplashScreen.this,"status");
Log.d("status",status);
if (status.equals("1")){
Intent i=new Intent(SplashScreen.this,MainActivity.class);
startActivity(i);
}else{
Intent i=new Intent(SplashScreen.this,LoginActivity.class);
startActivity(i);
}
//Remove activity
finish();
} catch (Exception e) {
}
}
};
// start thread
background.start();
}
}
I've followed more than five tutorials now, still can't resolve the issue
Upvotes: 1
Views: 2244
Reputation: 2042
Follow this article. It clearly says
Splash Screen is what the screen shows before it is able to start inflating the UI is the window background that the theme of the launch activity specifies. So the first thing we need is a special theme for the launch activity.
I have implemented splash screen by following this article. So you don't need to create any splash screen activity. Just convert your text to a drawable resource and use it as background in splash screen theme for your launch activity.
Upvotes: 2
Reputation: 10906
The only thing that looks glaringly wrong is your calling StartAnimations in onCreate. You want to do that in onResume instead. I would also try to break this into steps to see if each step works to debug it. Step 1 for me would be defaulting the background to say red and seeing if it shows up. Then I would try setting it to 50% red to see if the alpha works correctly. Then I would try to test your animations one at a time, first the background animation followed by the translate animation. Breaking this into smaller pieces that you get to successively work will make this much easier to solve.
Since you are starting the animation in onCreate my guess as to what is currently happening it that your animation is finished running before the Activity has rendered for the first time. Remember it won't render until in onResume. And since white is the default color of the activity all you see is a white screen show for a few seconds and then your second activity.
Also given your design where you want the background to fade in, you are going to need to set android:background in the theme that you set to that activity in the manifest. If you don't do that what you are going to see happen (when you implement this correctly) is a white screen for about .5-2 seconds followed by it then turning transparent when it begins running your splash screen animations.
Upvotes: 0