본문 바로가기

Android Studio

(Android Studio) 스플래시액티비티 이용 방법

336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

화면 5초간 있다가 메인으로 이동예제 이다.


출처 : 


http://suspected.tistory.com/entry/%EC%B4%88%EA%B8%B0-%EB%A1%9C%EB%94%A9%ED%99%94%EB%A9%B4splash%EB%9D%84%EC%9A%B0%EA%B8%B0


위의 사이트 보고서 만들어 본 소스 예제


MainActivity.java


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package kr.co.skills.study_160517;
 
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
 
public class MainActivity extends AppCompatActivity {
 
    Button Button1;
 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
 
        startActivity(new Intent(this, SplashActivity.class));
 
        setContentView(R.layout.activity_main);
 
        Button Button1 = (Button)findViewById(R.id.Button1);
 
        Button1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
 
                Intent myIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://m.naver.com"));
 
                startActivity(myIntent);
            }
        });
    }
}
 
cs


SplashActivity.java


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
package kr.co.skills.study_160517;
 
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v7.app.AppCompatActivity;
 
 
public class SplashActivity extends AppCompatActivity {
 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash);
 
        Handler handler = new Handler(){
            public void handleMessage(Message msg){
                finish();
 
            }
        };
        // TODO Auto-generated method stub
        handler.sendEmptyMessageDelayed(0,5000);
    }
}
 
cs


activity_main.xml


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="kr.co.skills.study_160517.MainActivity">
 
    <Button
        android:id="@+id/Button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello" />
</RelativeLayout>
 
cs


activity_splash.xml


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
    tools:context="kr.co.skills.study_160517.SplashActivity">
 
    <ImageView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:src="@drawable/background"
        android:scaleType="fitXY"/>
 
</RelativeLayout>
 
cs



==============


스플래시 액티비티 오류 시 사용


출처 : http://m.blog.daum.net/andro_java/588


스플래시 액티비티 오류


// Performing stop of activity that is not resumed // 스플래시 액티비티 시 오류

    private boolean isIntro = false;

    @Override

    protected void onPostResume() {

        if (! isIntro) {

            // Splash 화면 띄우기

            startActivity(new Intent(this, SplashActivity.class));

            isIntro = true;

        }

        super.onPostResume();

    }