SplashScreen richtig einbinden

  • Antworten:2
max theis
  • Forum-Beiträge: 31

07.09.2010, 09:34:30 via Website

Guten Morgen,

ich hätte mal eine Frage, ich hab mir einen SplashScreen erstellt, den ich zum Anfang des Programms und zum Ende als Aktion auf den Exit Button einblenden möchte. Mein Menü hatte ich bereits als erstes erstellt, so dass meine erste Activity ist. Ich hoffe ihr könnt mir weiter helfen.

Basic manifest

1<?xml version="1.0" encoding="utf-8"?>
2<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3 package="com.test.basic"
4 android:versionCode="1"
5 android:versionName="1.0">
6 <application android:icon="@drawable/icon" android:label="@string/app_name">
7 <activity android:name=".Basic" android:label="@string/app_name">
8 <intent-filter>
9 <action android:name="android.intent.action.MAIN" />
10 <category android:name="android.intent.category.LAUNCHER" />
11 </intent-filter>
12 </activity>
13 <activity android:name=".ShowAnzeige" android:label="@string/anzeiger">
14 </activity>
15
16</application>
17 <uses-sdk android:minSdkVersion="6" />
18
19</manifest>

SplashScreen.java

1public class SplashScreen extends Activity {
2
3 public void onCreate(Bundle savedInstanceState) {
4 super.onCreate(savedInstanceState);
5 setContentView(R.layout.splash);
6 Thread splashThread = new Thread() {
7 @Override
8 public void run() {
9 try {
10 int waited = 0;
11 while (waited < 5000) {
12 sleep(100);
13 waited += 100;
14 }
15 } catch (InterruptedException e) {
16 // do nothing
17
18 } finally {
19 finish();
20 Intent i = new Intent();
21 i.setClassName("com.test.basic",
22 "com.test.basic.Basic");
23 startActivity(i);
24 }
25 }
26 };
27 splashThread.start();
28 }


Basic,java // Meine HauptKlasse mit Hauptmenü

1public class Basic extends Activity implements OnClickListener {
2
3 private Button ngButton;
4 private Button hsButton;
5 private Button close;
6
7 @Override
8 public void onCreate(Bundle savedInstanceState) {
9 super.onCreate(savedInstanceState);
10 setContentView(R.layout.main);
11
12 ngButton = (Button) findViewById(R.id.newgame_button);
13 ngButton.setOnClickListener(this);
14
15 hsButton = (Button) findViewById(R.id.highscore_button);
16
17 close= (Button) findViewById(R.id.exit_button);
18
19 }
20
21 @Override
22 public void onClick(View v) {
23
24 EditText nameField = (EditText) findViewById(R.id.name_field);
25
26 String name = nameField.getText().toString();
27
28 if (name.length() == 0) {
29 new AlertDialog.Builder(this).setMessage(
30 R.string.error_name_missing).setNeutralButton(
31 R.string.error_ok,
32 null).show();
33 return;
34 }
35
36
37 if (v== ngButton){
38
39 Intent intent = new Intent();
40
41 intent.setClass(Basic.this, ShowAnzeige.class);
42 startActivity(intent);
43 }
44
45 if (v==close){
46 Intent intentsplash = new Intent();
47
48 //intentsplash.setClass(Basic.this, )
49 }
50
51
52 }
53
54}


Vielen Dank.

Gruß
max

Antworten
Mac Systems
  • Forum-Beiträge: 1.727

07.09.2010, 09:38:11 via Website

Ich verstehe deine Frage nicht !

Windmate HD, See you @ IO 14 , Worked on Wundercar, Glass V3, LG G Watch, Moto 360, Android TV

Antworten
max theis
  • Forum-Beiträge: 31

07.09.2010, 09:47:39 via Website

Ja okay, kann ich gut verstehn, ich hab mich auch nicht klar genug ausgedrückt. Also noch mal genauer.

Ich möchte beim Start meines Programm einen SplashScreen einbinden, leider weiß ich nicht wie ich den in meiner Manifest einbinden soll, soll ich sie als meine Hauptklasse einbinden und meine Hauptklasse als nebenactivity behandeln ? oder kann ich Sie als Nebenactivity einbinden so wie ich das mit der ShowAnzeige mache,

Dann habe ich ein Exit Button, womit ich auch den SplashScreen aufrufen möchte und anschließend das Programm ganz beenden.

Ich hoffe ich konnte es ein bisschen genauer erklären = )

Antworten