Code for QuizSplashActivity:
package com.androidbook.triviaquiz;
import java.text.DateFormat;
import java.util.Date;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.AnimationUtils;
import android.view.animation.LayoutAnimationController;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;
public class QuizSplashActivity extends QuizActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
String rest="First Time Launched";
String launchd=DateFormat.getDateInstance().format(new Date());
String launcht=DateFormat.getTimeInstance().format(new Date());
String ldt=launchd+" "+launcht;
SharedPreferences set=getSharedPreferences(GAME_PREFERENCES,MODE_PRIVATE);
if(set.contains("lastLaunch"))
{rest=set.getString("lastLaunch", "default");
}
Log.i("LaunchInfo",rest);
SharedPreferences.Editor edit=set.edit();
edit.putString("lastLaunch",ldt);
edit.commit();
setContentView(R.layout.splash);
anime();
}
private void anime()
{TextView t1=(TextView)findViewById(R.id.TextViewTopTitle);
Animation f1=AnimationUtils.loadAnimation(this, R.anim.fade_in);
t1.startAnimation(f1);
TextView t2=(TextView)findViewById(R.id.TextViewBotTitle);
Animation f2=AnimationUtils.loadAnimation(this, R.anim.fade_in2);
//t2.startAnimation(f2);
// Animation fade2 =AnimationUtils.loadAnimation(this, R.anim.fade_in2);
//View.startAnimation(fade2);
t2.startAnimation(f2);
AnimationListener animListener=new AnimationListener() {
public void onAnimationEnd(Animation animation){
startActivity(new Intent(QuizSplashActivity.this,QuizMenuActivity.class));
QuizSplashActivity.this.finish();
}
public void onAnimationRepeat(Animation animation) {
}
public void onAnimationStart(Animation animation) {
}
};
f2.setAnimationListener(animListener);
Animation spinin=AnimationUtils.loadAnimation(this,R.anim.custom_anim);
LayoutAnimationController controller=new LayoutAnimationController(spinin);
TableLayout tb=(TableLayout) findViewById(R.id.tableLayout1);
for(int i=0;i<tb.getChildCount();i++)
{TableRow row=(TableRow) tb.getChildAt(i);
row.setLayoutAnimation(controller);
}
}
@Override
protected void onPause()
{super.onPause();
TextView t1=(TextView)findViewById(R.id.TextViewTopTitle);
t1.clearAnimation();
TextView t2 =(TextView)findViewById(R.id.TextViewBotTitle);
t2.clearAnimation();
TableLayout tb=(TableLayout) findViewById(R.id.tableLayout1);
for(int i=0;i<tb.getChildCount();i++)
{TableRow row=(TableRow) tb.getChildAt(i);
row.clearAnimation();
}
}
@Override
protected void onResume()
{super.onResume();
anime();
}
}
Code for QuizMenuActivity
package com.androidbook.triviaquiz;
import android.os.Bundle;
public class QuizMenuActivity extends QuizActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.menu);
}
}
After the animations in splash have played out (Specifically fade_in2) the QuizMenuActivity is supposed to be launched and splash finished. The Animations play out fine but the QuizMenuActivity doesn’t seem to be launched. Playing around with the debugger/break points it seems the program flow never goes into onAnimationEnd (Animation animation) method. Though I might be wrong as I am pretty new with eclipse and android.
I’ve fixed the code based on the first reply and updated it.Now the listner is firing but after the start activity i get ‘application has beenstopped unexpectedly.Please try again.Force Close’.Seems to be while in something called ZygoteInit$MethodAnd.
Is this the callstack:
tiv [Android Application]
DalvikVM[localhost:8612]
Thread [<3> main] (Running)
Thread [<13> Binder Thread #2] (Running)
Thread [<11> Binder Thread #1] (Running)
I think the callstacks supposed to be in the logcat but I’m getting ‘Unable to open stack trace file ‘/data/anr/traces.txt’: Permission denied’ error log in logcat.
Also the appliction seems to crash before the the animation f2(which is what is being listened for) has been displayed.t2 never gets displayed.
-change manifest to this
-It solved my problem
-add dot in the beginning of activity name, not sure why or if it is necessary !