【发布时间】:2017-08-12 08:15:01
【问题描述】:
我对编码真的很陌生,几乎不知道自己在做什么。
我需要让这个启动画面工作,但它一直在启动画面和 mainactivity 之间无限循环,我不知道为什么,我从一些 YouTube 视频中删除了代码,视频也没有解释,所以我卡住了。
这是mainactivity的代码:
package sg.edu.tp.project1;
import android.content.Intent;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageButton;
public class MainActivity extends AppCompatActivity {
private static int SPLASH_TIME_OUT = 1000;
private ImageButton Search01;
private ImageButton Mymusic;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Search01 = (ImageButton) findViewById(R.id.Search);
Mymusic = (ImageButton) findViewById(R.id.Mymusic);
}
{ new Handler().postDelayed(new Runnable(){
@Override
public void run() {
Intent homeIntent = new Intent(MainActivity.this,
HomeActivity.class);
startActivity(homeIntent);
finish();
}
},SPLASH_TIME_OUT);
}
public void gotoSearchpage(View view){
Intent intent = new Intent(this, searchpage.class);
this.startActivity ( intent );
}
public void gotoMymusic(View view){
Intent intent = new Intent(this, myMusic.class);
this.startActivity ( intent );
}
public void gotoPlaylist(View view){
Intent intent = new Intent(this, playlist.class);
this.startActivity ( intent );
} }
这是启动画面的代码:
package sg.edu.tp.project1;
import android.content.Intent;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
public class HomeActivity extends AppCompatActivity {
private static int SPLASH_TIME_OUT = 1000;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
}
{ new Handler().postDelayed(new Runnable(){
@Override
public void run() {
Intent homeIntent = new Intent(HomeActivity.this,
MainActivity.class);
startActivity(homeIntent);
finish();
}
},SPLASH_TIME_OUT);
}
}
【问题讨论】:
-
在不使用处理程序的情况下启动意图
标签: android loops screen splash-screen