Android Splash Screen ProgressBar color not change - android

I am making a Splash Screen in my App. I have to set ProgressBar in my Splash Screen. But ProgressBar show green color, I have to set White color using code But It work after some time. First it show green color then it become white.
To Create ProgressBar I have use this https://github.com/rahatarmanahmed/CircularProgressView
any Help be Appreciated.
Java code :
public class SplashScreenActivity extends Activity {
// Set Duration of the Splash Screen
CircularProgressView progressView;
private static int SPLASH_TIME_OUT = 3000;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Remove the Title Bar
requestWindowFeature(Window.FEATURE_NO_TITLE);
// Get the view from splash_screen.xml
setContentView(R.layout.splash_screen);
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
progressView = (CircularProgressView) findViewById(R.id.progress_view);
progressView.setColor(Color.parseColor("#FFFFFF"));
finish();
Intent myIntent = new Intent(SplashScreenActivity.this,
MainActivity.class);
startActivity(myIntent);
}
}, SPLASH_TIME_OUT);
}
}

Try this code it will work.
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
progressView = (CircularProgressView) findViewById(R.id.progress_view);
progressView.getIndeterminateDrawable().setColorFilter(getResources().getColor(R.color.accent_dark),
PorterDuff.Mode.SRC_IN);
finish();
Intent myIntent = new Intent(SplashScreenActivity.this,
MainActivity.class);
startActivity(myIntent);
}
}, SPLASH_TIME_OUT);

After changing the code alternative it will work perfectly put the ProgressBar intialization and setcolor property before the Handler code look at the code :
public class SplashScreenActivity extends Activity {
// Set Duration of the Splash Screen
CircularProgressView progressView;
private static int SPLASH_TIME_OUT = 3000;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Remove the Title Bar
requestWindowFeature(Window.FEATURE_NO_TITLE);
// Get the view from splash_screen.xml
setContentView(R.layout.splash_screen);
progressView = (CircularProgressView) findViewById(R.id.progress_view);
progressView.setColor(Color.parseColor("#FFFFFF"));
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
finish();
Intent myIntent = new Intent(SplashScreenActivity.this,
MainActivity.class);
startActivity(myIntent);
}
}, SPLASH_TIME_OUT);
}
}

Related

I have a problem with Intent in my splash screen

i build app when open the app splash screen working but after 3 second Instead of going to another page, it closes the application
my codes are:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_menu);
ImageView iv = findViewById(R.id.iv);
Animation myanim = AnimationUtils.loadAnimation(this, R.anim.mytransition);
iv.startAnimation(myanim);
final Intent intent0 = new Intent(Menu.this, Fehrest.class);
Thread timer;
timer = new Thread() {
public void run () {
try {
sleep(3000);
} catch (InterruptedException e) {
e.printStackTrace();
}
finally {
startActivity(intent0);
finish();
}
}
};
timer.start();
}
}
I dont know this will be helping you, maybe you can try change your code like this or you can add your logcat error for making error is clear
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_menu);
ImageView iv = findViewById(R.id.iv);
Animation myanim = AnimationUtils.loadAnimation(this, R.anim.mytransition);
iv.startAnimation(myanim);
// redirect to another activity
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
startActivity(new Intent(Menu.this, Fehrest.class));
finish();
}
}, 3000);
}
for just test purpose remove finish method from splash Activity. and check your another application close or not. if another Activity close then may you use finish method on another activity.
please try this hope it will help you...
public class MainActivity extends AppCompatActivity {
private ImageView iv;
private static int splashTimeOut=3000;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
iv=(ImageView)findViewById(R.id.iv);
methodLogin();
}
private void methodLogin() {
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
Intent i=new Intent(getApplicationContext(),Fehrest.class);
startActivity(i);
finish();
}
},splashTimeOut);
Animation myanim = AnimationUtils.loadAnimation(this,R.anim.mytransition);
iv.startAnimation(myanim);
}
}

Android app start up animation

i just need to know how is it possible to create a start-up animation in your app. When the app is launched I would like it to go through custom animation and then it reaches the content of the app (main activity) ...
Thanks for all your help
If you really want a "startup" screen, just load up another activity before the MainActivity and display that screen for x amount of time:
public class SplashScreen extends Activity {
// Splash screen timer
private static int TIME_OUT = 5000;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash_layout);
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
Intent i = new Intent(SplashScreen.this, MainActivity.class);
startActivity(i);
finish();
}
}, TIME_OUT);
}
}

how to check if an application is killed during an animation in android

i have to make an application in which it starts with an animation and if we click the back button then it should return back to application manager.But what i have made in it if u click back button during that animation then it goes to application manager but after a second or two the first page(the one after this animation comes up).
Can anyone help??
This is the animation..
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.load);
im = (ImageView) findViewById(R.id.load_icon);
rotate = AnimationUtils.loadAnimation(getApplicationContext(),
R.anim.load_page);
rotate.setInterpolator(new LinearInterpolator());
im.startAnimation(rotate);
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
Intent nextPageIntent = new Intent(getApplicationContext(),
P1.class);
startActivity(nextPageIntent);
}
}, 3000);
}
The first page opens because you have added
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
Intent nextPageIntent = new Intent(getApplicationContext(),
P1.class);
startActivity(nextPageIntent);
}
}, 3000);
This launches the activity.For knowing if the animation has stopped use AnimationListener. More details here about animation listener
Android, How to set animation listener for view group?
You just added animation to one image view thats all, you do not doing anything with animation. The problem is, you started one thread to start activity P1 after 3 seconds. That thread only starting P1 activity. Try this and try to avoid killProcess(),
public class LauncherActivity extends Activity {
private Handler mHandler;
private Runnable mRunnable;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_launcher);
mHandler = new Handler();
mRunnable = new Runnable() {
#Override
public void run() {
Intent nextPageIntent = new Intent(getApplicationContext(),
XmlParserActivity.class);
startActivity(nextPageIntent);
}
};
mHandler.postDelayed(mRunnable, 3000);
}
/* #Override
public void onBackPressed() {
super.onBackPressed();
mHandler.removeCallbacks(mRunnable);
}*/
#Override
protected void onDestroy() {
super.onDestroy();
mHandler.removeCallbacks(mRunnable);
}
}
public void onBackPressed() {
android.os.Process.killProcess(android.os.Process.myPid());
}
This is the answer

Android change Activity after few seconds

I need some help with my first Android project.
I want to write a app which is showing you a picture with a ImageView for a few seconds I would say so about 4 seconds and after that it change to a second activity which shows a button(only for testing).
My Problem is that my app after I started it in my AVD jump over the picture and shows immediately the button.
How can I fix it? I looked up so long and tried so many things I hope someone of you have a idea :)
Thanks for helping
Here my Code of my MainActivity:
package com.example.parkourspots;
public class MainActivity extends Activity {
private ViewTreeObserver vto;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final View myLayout = findViewById(R.id.startscreen);
vto = myLayout.getViewTreeObserver();
vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener(){
#Override
public void onGlobalLayout(){
try {
Thread.sleep(500);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Intent intent = new Intent(MainActivity.this, select_activity_class.class);
startActivity(intent);
}
});
}}
Check this code.
package com.example.parkourspots;
public class MainActivity extends Activity {
private static int TIME_OUT = 4000; //Time to launch the another activity
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final View myLayout = findViewById(R.id.startscreen);
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
Intent i = new Intent(MainActivity.this, ActivityTwo.class);
startActivity(i);
finish();
}
}, TIME_OUT);
}
});
You can try:
public class MainActivity extends Activity {
private Handler mHandler = new Handler();
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mHandler.postDelayed(new Runanble() {
#Override
public void run() {
Intent intent = new Intent(MainActivity.this, select_activity_class.class);
startActivity(intent);
}
}, 4000); // 4 seconds
}
}
In addiction, you may add this for your second activity declaration in AndroidManifest: android:finishOnTaskLaunch="true"
never stall the UI thread. The UI thread is responsible for keeping your app feeling responsive.
But this is an fast and alternative solution for your problem.
public class MyActivity extends Activity {
private Handler mHandler = new Handler();
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mHandler.postDelayed(new Runnable() {
public void run() {
doStuff();
}
}, 5000);
}
private void doStuff() {
Intent intent = new Intent(MainActivity.this, select_activity_class.class);
startActivity(intent);
}
}
Then 5 seconds after the intent must start.
But i recommend async task
1)Sleeping 500 only sleeps for .5 seconds. So it would blink quickly anyway
2)Sleeping doesn't allow the thread to get back to the looper, so it freezes your UI. This means it won't update and draw anyway. Use a timer instead. Or posting a message to a handler would be acceptable here.
The problem is you're only sleeping for 500 milliseconds (half of one second), so it makes sense that it happens seemingly-immediately. You're also going to want to remove the OnGlobalLayoutListener after it's called. Here's an example of an approach that should work for you:
final Handler handler = new Handler(); // Create a Handler on the main Thread
vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener(){
#Override
public void onGlobalLayout(){
removeOnGlobalLayoutListener(vto, this);
handler.postDelayed(new Runnable(){
public void run(){
Intent intent = new Intent(MainActivity.this, select_activity_class.class);
startActivity(intent);
}
}, 4000); //Post back to the main Thread after 4000 mils (4 seconds)
}
});
#SuppressLint("NewApi")
public static void removeOnGlobalLayoutListener(View v, ViewTreeObserver.OnGlobalLayoutListener listener){
if (Build.VERSION.SDK_INT < 16) v.getViewTreeObserver().removeGlobalOnLayoutListener(listener);
else v.getViewTreeObserver().removeOnGlobalLayoutListener(listener);
}
Proper and short solution
Make a handler and give them a delay to call back itself:
final Handler h = new Handler();
h.postDelayed(new Runnable() {
#Override
public void run() {
//Do something after 1s
}
}, 1000);
Remember that 1 sec = 1000 milliseconds
Adjust time with that formula.
Happy Coding.

Android Activity Splash Screen

I have a splash screen which displays for 2-3 sec before it disappears.
I want to add a Fade in Effect when the next activity is loaded. I saw an Example in the Facebook Hacker Example and i am using it.
It uses a finish(); to end that activity to so from the DashboardActivity if some one clicks back it doesnt return back to the SplashAcitivty. But using this doesnt create the Fade in Effect as show in the API demos Examples.
public class SplashActivity extends Activity {
private long splashDelay = 3000;
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
// Remove title bar
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
// Remove notification bar
/*
* this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
* WindowManager.LayoutParams.FLAG_FULLSCREEN);
*/
setContentView(R.layout.activity_splash);
TimerTask task = new TimerTask() {
#Override
public void run() {
finish();
startActivity(new Intent().setClass(SplashActivity.this,
MainActivity.class));
overridePendingTransition(R.anim.fade, R.anim.hold);
}
};
Timer timer = new Timer();
timer.schedule(task, splashDelay);
}
}
Use a handler for this:
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
startActivity(new Intent(SplashActivity.this,
MainActivity.class));
overridePendingTransition(R.anim.fade, R.anim.hold);
finish();
}
}, splashDelay);

Categories

Resources