无法启动新活动。与 onAnimationEnd 有关吗?
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();
}
}
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);
}
}
在启动画面中的动画播放完毕(特别是 fade_in2)后,QuizMenuActivity
应该启动并启动启动画面结束。动画播放得很好,但 QuizMenuActivity
似乎没有启动。使用调试器/断点,程序流程似乎永远不会进入 onAnimationEnd(动画动画)方法。虽然我可能是错的,因为我对 eclipse 和 android 还很陌生。
我已经根据第一个回复修复了代码并更新了它。现在列表器正在触发,但在启动活动后我得到“应用程序已意外停止。请重试。强制关闭”。似乎是在名为 ZygoteInit$ 的东西中方法和。
这是调用堆栈吗:
tiv [Android Application]
DalvikVM[localhost:8612]
Thread [<3> main] (Running)
Thread [<13> Binder Thread #2] (Running)
Thread [<11> Binder Thread #1] (Running)
我认为调用堆栈应该位于 logcat 中,但我在 logcat 中收到“无法打开堆栈跟踪文件'/data/anr/traces.txt':权限被拒绝”错误日志。 此外,应用程序似乎在动画 f2(正在监听的动画)显示之前崩溃。t2 永远不会显示。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
- 将清单更改为此
-它解决了我的问题
- 在活动名称的开头添加点,不知道为什么或是否有必要!
-change manifest to this
-It solved my problem
-add dot in the beginning of activity name, not sure why or if it is necessary !
看来您正在将动画侦听器添加到“fade2”动画对象。但是该动画未设置为任何视图,例如
如果不启动视图的动画,侦听器将不会触发。
It seems you are adding the animation listener to the 'fade2' animation object. But that animation is not set to any view like
Without starting the animation for a view the listener will not fire.