Launching Android app Icon Shows Misbehavior or delay? - android

i'm facing a delay of like 0.3 milli sec in showing the splash screen in my application.
When it launches black screen with a top header appears with app icon over the left for like 0.3 or 0.2 milli sec, then the splash screen displays[launcher activity]. I had this Splash activity set as launcher activity and it displays for 5 seconds, and there's no delay set manually in code. It can be happening if app is heavy or something i had missed in coding. pls help.
code:
public class SplashScreen extends Activity {
// Splash screen timer
private static int SPLASH_TIME_OUT = 5000;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.splashscreen);
new Handler().postDelayed(new Runnable() {
/*
* Showing splash screen with a timer.
*/
#Override
public void run() {
// This method will be executed once the timer is over
Intent i = new Intent(SplashScreen.this, TabBar.class);
startActivity(i);
// close this activity
finish();
}
}, SPLASH_TIME_OUT);
}
}

Change your Splash Activity Theme in your Manifest
#android:style/Theme.Light.NoTitleBar.Fullscreen
or #android:style/Theme.Light.NoTitleBar
depends on your requirement

I Think you need to change or custom the app theme from manifest file: you will find it at :
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >

I can't change theme because of API level constraints, I did find the answer :
in values/styles
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
<item name="android:windowNoTitle">true</item>
<item name="android:windowFullscreen">true</item>
</style>
It seems like it was the titlebar that was the issue actually.
Though there's another problem appears: a white splash appears and then my splash Image for 0.2 to 0.3 miliseconds what to do now??
Any suggestions??

Related

Android app icon click takes too much time to open

On clicking on android app icon, app takes lot of time to open and then white screen appears before launching MainActivity.
splash_drawable.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:drawable="#drawable/splash_screen"
android:gravity="center" />
</layer-list>
styles.xml
<style name="LauncherLogoTheme" theme="Theme.AppCompat.NoActionBar">
<item name="android:windowBackground">#drawable/sdp_launcher_background</item>
</style>
manifest file
<activity
android:name=".SplashActivity"
android:configChanges="orientation|keyboardHidden"
android:noHistory="true"
android:theme="#style/LauncherLogoTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
SplashScreenActivity
public class SplashActivity extends AppCompatActivity {
#Override
protected void onCreate(#Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
startActivity(new Intent(SplashActivity.this, MainActivity.class));
finish();
}
}
Please help on how to use splash screen in a correct way
If you have seen some apps using a splash screen, you must have noticed that they stay on the splash screen for 1 or half a second. Which is a standard for a splash screen. Mostly splash screen is white and an image generally with app icon/logo and app name.
Coming to your issue; the issue with your code is that you start another activity when the current activity is just created and just after that you are finishing it. I also don't see setContentView().
The recommended approach is to use a Handler and use a delayed callback to start the next activity and finish the current one.
public class SplashActivity extends AppCompatActivity {
#Override
protected void onCreate(#Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
new Handler(Looper.myLooper()).postDelayed(new Runnable() {
#Override
public void run() {
startActivity(new Intent(SplashActivity.this, MainActivity.class));
finish();
}
},1000);
}
}
Delayed starting of next activity and finishing of the current for 1 Second(1000 ms). Which will allow the Splash activity to be created and then resumed(become visible to user) smoothly before it is finished.

White screen at app startup - Splash Screen [duplicate]

This question already has answers here:
Android - Prevent white screen at startup
(18 answers)
Closed 4 years ago.
I created a splash screen for my application using an empty activity that stays visible for 3 seconds with a background image.
Usually, the application starts with a white screen before the background image becomes visible, however, some applications are already started with the "real" splash screen image.
How to implement this?
you can use splash screen in this way.
Add style for splash screen activity in styles.xml
<style name="SplashTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowBackground">#drawable/yourImageName</item>
</style>
Add that style as theme to your SplashScreenActivity in manifest file
<activity android:name=".SplashScreenActivity"
android:theme="#style/SplashTheme"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Remove setContentView() in SplashScreenActivity's onCreate() Method and use it as a java file which extends AppCompactActivity
The problem is because system process draws initial blank screen when launching the app, from documentation:
A common way to implement a themed launch screen is to use the windowDisablePreview theme attribute to turn off the initial blank
screen that the system process draws when launching the app. However,
this approach can result in a longer startup time than apps that don’t
suppress the preview window. Also, it forces the user to wait with no
feedback while the activity launches, making them wonder if the app is
functioning properly.
You can disable it with windowDisablePreview attribute, something like this:
<application
...
android:windowDisablePreview="true">
...
</application>
Splash Activity usually starts with the background.
Try this code, it might help you.
Code for your splash activity page.
public class SplashScreen extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash_screen);
Thread myThread = new Thread(){
#Override
public void run() {
try {
sleep(3000);
Intent intent = new Intent(getApplicationContext(),MainActivity.class);
startActivity(intent);
finish();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
};
myThread.start();
}}
In layout file, you need to include just Image which you want to see on the splash page.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/activity_splash_screen"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000000">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="#drawable/capture"
/>
</RelativeLayout>
And make sure you add the Splashscreen page before Main activity in Manifest.
<activity android:name=".SplashScreen">

Android: Black Screen between Activity

When I go one activity to another activity , between the transaction a Black screen is come for some seconds. I properly finish the activity before calling startActvity().
Am using android:theme="#android:style/Theme.Translucent" theme for my activity. Even though between the activity transaction a black screen is coming
Can any one please tell me how to resolve this
Thanks in advance :)
There is no need to finish activity before calling startActivity().
Make sure that you have set content view in the onCreate of called Activity and that you are not blocking UI thread (check onCreate, onStart and onResume if you have override them).
You don't need to manage finshing your activity, this will be managed automatically when the activity is no longer in view. Just use:
startActivity(new Intent(this, MyNextActivity.class));
And use this code in whatever method you are using to navigate the activity changes.
If you make sure your window is the background of your activities you can set the window background to a color other than black:
<item name="android:windowBackground">#drawable/window_background</item>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<solid android:color="#color/window_background"/>
</shape>
windowBackground in Android 6 (Marshmallow)
The other option is to manage transitions, so there is no gap between the end of the first transition and the beginning of the second. However, you have not mentioned transitions.
How to remove the delay when opening an Activity with a DrawerLayout?
for disable this default animation create one style:
<style name="noAnimTheme" parent="android:Theme">
<item name="android:windowAnimationStyle">#null</item>
</style>
and set it as theme for your activity in the manifest:
<activity android:name=".ui.ArticlesActivity" android:theme="#style/noAnimTheme">
</activity>
Assumption :-
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.xyz);
// comment code here
}
If you go from activity A to B then try to comment code in OnCreate , OnResume in Activity B Like this and check what happen still black screen is coming or not.If coming then try to change theme.
If you have a finish() or FLAG_ACTIVITY_CLEAR_TASK - a blank screen may show up on pre ICS devices
To avoid this black screen you have to add one line in intent
overridePendingTransition (0, 0);
Example(kotlin):
val intent = Intent(applicationContext, MainActivity::class.java)
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
startActivity(intent)
overridePendingTransition (0, 0)
Example(Java):
Intent intent = new Intent(getApplicationContext(), MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
overridePendingTransition (0, 0);

ActionBarSherlock top-left icon doesn't navigate up

I am using ActionBarSherlock to implement ActionBar for both Pre/post versions of Android HoneyComb.
My problem is that when I tap top-left icon on Android version 4.0.4, it did not respond.
Here is what I have done till now:
1) In all style folders "values/styles.xml" , "values-v11/styles.xml" & "values-v14/styles.xml"; I have done the following
<style name="ActivityTheme" parent="#style/AppTheme">
<item name="actionBarStyle">#style/ActivityActionBarStyle</item>
<item name="android:actionBarStyle">#style/ActivityActionBarStyle</item>
</style>
<style name="ActivityActionBarStyle" parent="ommaralrd_transparent_ActionBar">
<item name="displayOptions">showHome|showTitle|homeAsUp</item>
<item name="android:displayOptions">showHome|showTitle|homeAsUp</item>
</style>
In any application activity (except Home activity since it should not have Up arrow), I have done the following:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_inner);
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB){
getSupportActionBar().setDisplayHomeAsUpEnabled(false);
}
.....rest of my code ...
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
Intent intent;
switch (item.getItemId()) {
case android.R.id.home:
/*app icon in action bar clicked; go home*/
intent = new Intent(this, MainActivity.class);
/* With this flag, if the activity you're starting already exists in the current task,
* then all activities on top of it are destroyed and it is brought to the front.
* you should usually not create a new instance of the home activity. Otherwise,
* you might end up with a long stack of activities in the current task with multiple
* instances of the home activity.*/
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
break;
default:
return super.onOptionsItemSelected(item);
}
return true;
}
In the Manifest file, I make sure that I have applied the respective style to all activities (except main activity since it should not have Up arrow)
<activity
android:name="com.andrid.example.TestActivity"
android:label="#string/app_name"
android:theme="#style/ActivityTheme" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.andrid.example.MainActivity" />
</activity>
So now when I test the application on Pre-HoneyComb version, the Up arrow is never shown which is correct since ABS can't respond at all if icon was tapped to navigate up.
But when I tried the application on Post-HoneyComb version like 4.1 on Emulator, the Up arrow is shown and when I tapped it, it works as expected and navigates up normally.
My problem is that when I tried the application on Android 4.0.4 emulator , the Up arrow is shown as expected but when I tapped it, it do nothing
I have found the fix:
Simply I should avoid set the Icon Home as Up using xml attribute: homeAsUp but instead I should have used setDisplayHomeAsUpEnabled(true) explicitly as follows:
In all style folders "values/styles.xml" , "values-v11/styles.xml" & "values-v14/styles.xml"; I have done the following
<style name="ActivityTheme" parent="#style/AppTheme">
<item name="actionBarStyle">#style/ActivityActionBarStyle</item>
<item name="android:actionBarStyle">#style/ActivityActionBarStyle</item>
</style>
<style name="ActivityActionBarStyle" parent="ommaralrd_transparent_ActionBar">
<item name="displayOptions">showHome|showTitle</item>
<item name="android:displayOptions">showHome|showTitle</item>
</style>
in Each Activity (except main activity):
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB){
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}

Disable default animation from Portrait to Landscape

I have an app with several 'normal' activities which can run on either landscape or portrait. They are designed for and mostly used on portrait.
This app has one single activity which uses the camera and is locked on landscape. I 'simulate' this activity is on portrait by rotating images and texts 90 degree, so it looks like the rest of activities.
On some device, such as Samsung Galaxy Tab 7 and Galaxy S3, a rotation animation is shown when going from a normal portrait activity to camera landscape activity and back. This is confusing for user because landscape activity simulates being on portrait.
Is there a way to remove this rotation animation? Ideally I'd like to change to default portrait to portrait animation, but just removing rotation animation would be enough.
I've tried
overridePendingTransition(0, 0);
an other variations of that method without success.
[ADDED]
Following suggestions by #igalarzab, #Georg and #Joe, I've done this (still with no luck):
Added android:configChanges="orientation|screenSize" to Manifest
Added onConfigurationChanged
Created a dummy animation which does nothing and added overridePendingTransition(R.anim.nothing, R.anim.nothing);
I had these results:
onConfigurationChanged is called only when rotating same Activity (Activity A on portrait -> Activity A on landscape). But it's not called when going from Activity A on portrait -> Activity B on landscape
This prevented Activity from being restarted when rotating, but it did NOT removed rotation animation (tested on Galaxy S3, Galaxy Nexus, Galaxy Tab 7.0 and Galaxy Tab 10.1)
overridePendingTransition(R.anim.nothing, R.anim.nothing); removed normal transitions (portrait->portrait and landscape->landscape) but it didn't removed rotation animation (portrait->landscape and vice versa).
[VIDEO]
I've uploaded a video that shows animation I want to disable. This happens when changing from camera activity (locked to landscape) to other activity while holding phone on portrait:
http://youtu.be/T79Q1P_5_Ck
Sorry there is no way to control the rotation animation. This is done way outside of your app, deep in the window manager where it takes a screenshot of the current screen, resizes and rebuilds the UI behind it, and then runs a built-in animation to transition from the original screenshot to the new rebuilt UI. There is no way to modify this behavior when the screen rotation changes.
This is the way how the stock camera app disables rotation animation:
private void setRotationAnimation() {
int rotationAnimation = WindowManager.LayoutParams.ROTATION_ANIMATION_CROSSFADE;
Window win = getWindow();
WindowManager.LayoutParams winParams = win.getAttributes();
winParams.rotationAnimation = rotationAnimation;
win.setAttributes(winParams);
}
Note: According to API Reference and comment below, this only works:
On API level 18 or above
The FLAG_FULLSCREEN flag is set for WindowManager.LayoutParams of the Activity
The Activity is not covered by another window (e.g. the Power Off popup triggered by long pressing the Power button)
You can set in the AndroidManifest a property called android:configChanges where you can decide which changes you want to manage in code. In this way, the rotation change animation will be disabled and you can handle it as you want in the method onConfigurationChanged of your Activity.
<activity
android:name=".MySuperClass"
android:label="#string/read_qrcode"
android:screenOrientation="portrait"
android:configChanges="orientation" />
android:rotationAnimation="seamless"
add this attribute in activity will reduce animation when rotate. I try to find it when i want to make smooth camera app
I've put that in the mainActivity and it cancelled the rotation animation:
#Override
public void setRequestedOrientation(int requestedOrientation) {
super.setRequestedOrientation(requestedOrientation);
int rotationAnimation = WindowManager.LayoutParams.ROTATION_ANIMATION_JUMPCUT;
Window win = getWindow();
WindowManager.LayoutParams winParams = win.getAttributes();
winParams.rotationAnimation = rotationAnimation;
win.setAttributes(winParams);
}
More details here.
You might have tried this already, but just in case:
Try defining a "do nothing" animation and call overridePendingTransition() with its id. Maybe something like:
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter="true">
<translate
android:fromXDelta="0"
android:toXDelta="0"
android:duration="100" />
</set>
Sorry, I didn't have a Galaxy device to test with :)
You can set in the AndroidManifest a property called
android:configChanges where you can decide which changes you want to
manage in code. In this way, the rotation change animation will be
disabled and you can handle it as you want in the method
onConfigurationChanged of your Activity.
This should work, but according to this page you should also add screenSize to configChanges by adding android:configChanges="orientation|screenSize" to your Activity Tag.
If you want to set your activities in portrait mode only you can do it in your manifest file like this
<activity
android:name=".Qosko4Activity"
android:label="#string/app_name"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Successfully checked on: Java - Android 9 (Pie) - Android Studio 4.1.3 - Huawei P10
For six months I could not solve this need. The problem was in the unassigned flag "FLAG_FULLSCREEN" in code.
First step MainActivity.java:
public class MainActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
/* getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN); */ // If the animation still is, try applying it.
setRotationAnimation();
}
private void setRotationAnimation() {
int rotationAnimation = WindowManager.LayoutParams.ROTATION_ANIMATION_JUMPCUT;
Window win = getWindow();
WindowManager.LayoutParams winParams = win.getAttributes();
winParams.rotationAnimation = rotationAnimation;
win.setAttributes(winParams);
}
public void Button (View view) {
// Connected to android:onClick="Button" in XML.
Intent intent = new Intent(MainActivity.this, MainActivity2.class);
startActivity(intent);
}
}
Next step MainActivity2.java:
public class MainActivity2 {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
/* getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN); */ // If the animation still is, try applying it.
setRotationAnimation();
}
private void setRotationAnimation() {
int rotationAnimation =
WindowManager.LayoutParams.ROTATION_ANIMATION_JUMPCUT;
Window win = getWindow();
WindowManager.LayoutParams winParams = win.getAttributes();
winParams.rotationAnimation = rotationAnimation;
win.setAttributes(winParams);
}
public void Button (View view) {
Intent intent = new Intent(MainActivity2.this, MainActivity.class);
startActivity(intent);
}
}
Next step styles.xml:
<resources>
<style name="AppTheme" parent="Theme.AppCompat.DayNight.NoActionBar">
<item name="android:windowFullscreen">true</item>
</style>
</resources>
Simple things I understood:
You must first anywhere start "setRotationAnimation()", before running activity2.
When start activity2 you have to run in it "setRotationAnimation()".
Works incorrectly.
Against them who said no I say yes it is possible and it is very simple! The first thing may sound stupid but lock your application to the desired orientation! Then keep asking the gyrometer what orientation the device has an last but not least rotate or animate your views to the new orientation!
Edit: you may want to hide the system ui since it won't rotate.
Mario

Categories

Resources