说明
SampleActivity1 有个图片闪烁的动画,点击按钮跳到SampleActivity2,返回SampleActivity1
这个代码在android上正常,但是在鸿蒙上不正常,返回10秒后SampleActivity2的onStop onDestroy 才会调用。(android 1秒内)
另外如果在SampleActivity2也 使用这个动画,返回SampleActivity1时,SampleActivity1的onStart有时候竟然不会调用???
有大佬研究下吗?
?
public class SampleActivity1 extends AppCompatActivity {
private static final String TAG = "SampleActivity1";
private ImageView mImageView; private Animation animation;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sample1);
mImageView = findViewById(R.id.img);
}
@Override
protected void onStart() {
super.onStart();
Log.e(TAG, "onStart: " );
start();
}
@Override
protected void onStop() {
super.onStop();
Log.e(TAG, " onStop" );
stop();
}
@Override
protected void onDestroy() {
super.onDestroy();
}
public void onNext(View view) {
Intent intent = new Intent(SampleActivity1.this, SampleActivity2.class);
startActivity(intent);
}
private void start() {
animation = new AlphaAnimation(1, 0); animation.setDuration(1000);//闪烁时间间隔
animation.setInterpolator(new AccelerateDecelerateInterpolator());
animation.setRepeatCount(Animation.INFINITE);
animation.setRepeatMode(Animation.REVERSE);
mImageView.setAnimation(animation);
// mImageView.startAnimation(animation);
}
private void stop(){
mImageView.clearAnimation();
if (animation != null) {
animation.cancel();
animation = null;
}
}
}
public class SampleActivity2 extends AppCompatActivity {
private static final String TAG = "SampleActivity2";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sample2);
}
@Override
protected void onDestroy() {
super.onDestroy();
Log.e(TAG, "onDestroy: 为什么会延时这么久才调用我");
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<ImageView
android:id="@+id/img"
android:layout_width="100dp"
android:layout_height="100dp"
android:background="@mipmap/ic_launcher"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="onNext"
android:text="next" />
</LinearLayout>
|