-
清单文件中先加载 欢迎页面 (WecomeActivity)在加载MainActivity
···
public class WecomeActivity extends Activity {
ImageView imageView ;
@Override
protected void onCreate(Bundle savedInstanceState) {//设置为无标题栏 /**标题是属于View的,所以窗口所有的修饰部分被隐藏后标题依然有效,需要去掉标题**/ requestWindowFeature(Window.FEATURE_NO_TITLE); //设置为全屏模式 getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); super.onCreate(savedInstanceState); //加载布局文件 setContentView(R.layout.activity_wecome); handler.sendEmptyMessageDelayed(0,3000); //主要用来发送延迟消息 } //首先新建一个消息处理对象,负责发送与处理消息 private Handler handler = new Handler() { @Override public void handleMessage(Message msg) { getHome(); super.handleMessage(msg); } }; public void getHome(){ //意图 Intent intent = new Intent(WecomeActivity.this, MainActivity.class); //启动Activity startActivity(intent); //关闭 finish(); }
}
···
2.里面开启转向的MainActiivty
3.在MainActiivty中用定时器转向 主页面(SecondActivity)
···
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
trun();
finish();
}
private void trun() {
//你要转向的Activity
final Intent intent= new Intent(MainActivity.this,SecondActivity.class);
Timer timer = new Timer();
TimerTask task = new TimerTask() {//定时器
@Override
public void run() {
startActivity(intent);
}
};
timer.schedule(task, 100);//两秒后
}
}
···
方式二:
通过引导页进入App
第一次运行通过3秒跳转到ViewPage 引导页,点击图片跳转到主页面
-
安装完成后,在运行 3秒延迟后直接跳转到主页面
一 1. 首先创建一个项目,准备三个Fragment 加载到第二个页面的Activity中
---------------------代码如下---------------------
···
public class SecondActivity extends FragmentActivity {
ArrayList<Fragment> list= new ArrayList<Fragment>();
ViewPager vp;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second);
init();
}private void init() {
vp=(ViewPager) findViewById(R.id.vp_second);
list.add(new Fist());
list.add(new Second());
list.add(new Three());
vp.setAdapter(new MyAdapter(getSupportFragmentManager()));
}
class MyAdapter extends FragmentPagerAdapter{public MyAdapter(FragmentManager fm) { super(fm); // TODO Auto-generated constructor stub } @Override public Fragment getItem(int arg0) { // TODO Auto-generated method stub return list.get(arg0); } @Override public int getCount() { // TODO Auto-generated method stub return list.size(); }
}
}
···
-------------------- --xml-文件
···
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="{relativePackage}.{activityClass}" >
<android.support.v4.view.ViewPager
android:id="@+id/vp_second"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical" >
</android.support.v4.view.ViewPager>
</LinearLayout>
···
在第三个Fragment中 有一个点击事件
···
public class Three extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.three, null);
view.findViewById(R.id.imageView1).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(getActivity(),ThreeActivity.class));
}
});
return view;
}
}
···
*******************MainActivity 中*****
···
package com.example.anqt;
import java.util.Timer;
import java.util.TimerTask;
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
public class MainActivity extends Activity {
private SharedPreferences sp;
SharedPreferences.Editor edit;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
sp = getSharedPreferences("second", MODE_PRIVATE);
edit = sp.edit();
sp.getBoolean("aa", false);
if (sp.getBoolean("aa", true)) {
new Thread(){
@Override
public void run() {
edit.putBoolean("aa", false);
edit.commit();
final Intent intent= new Intent(MainActivity.this,SecondActivity.class);
Timer timer = new Timer();
TimerTask task = new TimerTask() {
@Override
public void run() {
startActivity(intent);
}
};
timer.schedule(task, 3000);
}
}.start();
}else{
final Intent intent= new Intent(MainActivity.this,ThreeActivity.class);
Timer timer = new Timer();
TimerTask task = new TimerTask() {
@Override
public void run() {
startActivity(intent);
}
};
timer.schedule(task, 3000);
}
}
}
···