无法启动新活动。与 onAnimationEnd 有关吗?

发布于 2024-12-15 15:35:08 字数 4407 浏览 0 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

半岛未凉 2024-12-22 15:35:08

- 将清单更改为此
-它解决了我的问题
- 在活动名称的开头添加点,不知道为什么或是否有必要!

<?xml version="1.0" encoding="utf-8"?>
<manifest
    xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.androidbook.triviaquiz7"
    android:versionCode="1"
    android:versionName="1.0">
<application
    android:label="@string/app_name"
    android:debuggable="true"
    android:icon="@drawable/quizicon">
    <activity
        android:name=".QuizSplashActivity"
        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=".QuizGameActivity"></activity>
    <activity
        android:name=".QuizSettingsActivity"></activity>
    <activity
        android:name=".QuizScoresActivity"></activity>
    <activity
        android:name=".QuizHelpActivity"></activity>
    <activity
        android:name=".QuizMenuActivity"></activity>
</application>
<uses-sdk
    android:minSdkVersion="7" />

-change manifest to this
-It solved my problem
-add dot in the beginning of activity name, not sure why or if it is necessary !

<?xml version="1.0" encoding="utf-8"?>
<manifest
    xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.androidbook.triviaquiz7"
    android:versionCode="1"
    android:versionName="1.0">
<application
    android:label="@string/app_name"
    android:debuggable="true"
    android:icon="@drawable/quizicon">
    <activity
        android:name=".QuizSplashActivity"
        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=".QuizGameActivity"></activity>
    <activity
        android:name=".QuizSettingsActivity"></activity>
    <activity
        android:name=".QuizScoresActivity"></activity>
    <activity
        android:name=".QuizHelpActivity"></activity>
    <activity
        android:name=".QuizMenuActivity"></activity>
</application>
<uses-sdk
    android:minSdkVersion="7" />

我只土不豪 2024-12-22 15:35:08

看来您正在将动画侦听器添加到“fade2”动画对象。但是该动画未设置为任何视图,例如

view.startAnimation(fade2);

如果不启动视图的动画,侦听器将不会触发。

It seems you are adding the animation listener to the 'fade2' animation object. But that animation is not set to any view like

view.startAnimation(fade2);

Without starting the animation for a view the listener will not fire.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文