Android Splash Screen broken - android

i made a splash screen with this youtube video turtorial here ~> http://www.youtube.com/watch?v=IHg_0HJ5iQo
i saved my files and made sure they are there now when i send it to my device the splash screen does not show up.. i dont know why.
heres my activity_main.xml code
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:background="#drawable/back_background"
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=".MainActivity" >
</RelativeLayout>
here is my splash.xml code
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:background="#drawable/splash_background"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
</LinearLayout>
heres my manafest file
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.idoser"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.idoser.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>

So after talking in chat, I see that the reason your splash screen isn't showing up is because you're not doing anything with the splash.xml layout file. If you don't inflate your splash layout or set it as a content view, then you'll never see it.
There are several ways to do this but this is the approach that I would take:
Create a SplashActivity
Make SplashActivity your launcher Activity.
Use a timer to start your main activity.
SplashActivity.java
package com.example.idoser;
import android.app.Activity;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
public class SplashActivity extends Activity {
AsyncTask<Object, Object, Object> mTimerTask;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
}
#Override
protected void onResume() {
super.onResume();
if(mTimerTask != null) {
mTimerTask.cancel(false);
mTimerTask = null;
}
mTimerTask = new AsyncTask<Object, Object, Object>() {
#Override
protected Object doInBackground(Object... params) {
try {
Thread.sleep(3000); /* 3 second splash screen */
} catch(Exception e) { }
return null;
}
#Override
protected void onPostExecute(Object result) {
super.onPostExecute(result);
Intent intent = new Intent(SplashActivity.this, MainActivity.class);
startActivity(intent);
finish();
}
};
}
#Override
protected void onPause() {
super.onPause();
if(mTimerTask != null) {
mTimerTask.cancel(false);
mTimerTask = null;
}
}
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.idoser"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.idoser.SplashActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.example.idoser.MainActivity"
android:label="#string/app_name" >
</activity>
</application>
</manifest>
Mind you this is not the best possible way to do this but it should at least get your splash screen showing and give you an idea of the direction you need to go.

Related

Cant start new activity. It keeps crashing

When pressing the button, new activity should open but app instantly crashes. I have searched for answer and making a few adjustments to my code and only thing i dont know how to do is Manifest, can u help me with that?
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="Starting.Programm"
android:versionCode="1"
android:versionName="1.0">
<application android:label="#string/app_name"
android:icon="#drawable/ic_launcher">
<activity android:name="MainActivity"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="InformationActivity"
android:label="#string/app_name"
>
</activity>
</application>
MainActivity:
package Starting.Programm;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
public class MainActivity extends InformationActivity
{
/** Called when the activity is first created. */
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
public void startJourney(View view) {
Intent intent = new Intent(this, InformationActivity.class);
startActivity(intent);
}
}
main.xml
<?xml version="1.0" encoding="utf-8"?>
<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"
tools:context=".MainActivity"
>
<Button android:id="#+id/button_StartApp"
android:layout_width="100dp"
android:layout_height="60dp"
android:text="#string/button_StartApp"
android:layout_gravity="center"
android:layout_marginTop="70dp"
android:layout_marginLeft="115dp"
android:onClick="startJourney"
/>
</LinearLayout>
And next activity which should be opening
package Starting.Programm;
import android.app.Activity;
import android.os.Bundle;
class InformationActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.information);
}
}
<activity> android:name=".InformationActivity" </activity>
Remove android:label="#string/app_name" too. I don't think it is needed.
Add dot to end of pacakager name
package="Starting.Programm."

android app one page to another page not working

Here I done code for 5 buttons like Aboutus,development,carriers,services,contactus.
Here I clicked about us button that shows errors as unfortunately app closed.
Here is my code :
MainActivity.java
public class MainActivity extends Activity {
Button aboutus,development,service,carriers,contactus;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button aboutus=(Button) findViewById(R.id.aboutus);
aboutus.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
Intent i = new Intent(v.getContext(),aboutus.class);
startActivity(i);
}
});
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
activity_main.xml
<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=".MainActivity" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<Button
android:id="#+id/aboutus"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="About us"
/>
<Button
android:id="#+id/services"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Services"
/>
<Button
android:id="#+id/development"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Development"
/>
<Button
android:id="#+id/carriers"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Carriers"
/>
<Button
android:id="#+id/contactus"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Contact Us"
/>
</LinearLayout>
</RelativeLayout>
aboutus.java
public class aboutus extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.aboutus);
}
}
aboutus.xml
<?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" >
<TextView android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="Aboutus Page"/>
</LinearLayout>
AndroidManifest.xml is this correct ?
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.globalinfosoft"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.globalinfosoft.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<Activity android:name= "aboutus"/>
</application>
</manifest>
MainActivity.java
package com.example.a;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.View;
import android.widget.Button;
public class MainActivity extends Activity {
Button aboutus, development, service, carriers, contactus;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button aboutus = (Button) findViewById(R.id.aboutus);
aboutus.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
//Starting a new Intent
Intent nextScreen = new Intent(getApplicationContext(),aboutus.class);
startActivity(nextScreen);
}
});
}
}
Here is Androidmanifest.xml :
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.a"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.a.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.example.a.aboutus"></activity>
</application>
</manifest>
Instead of v.getContext() use 'getApplicationContext()'.
Intent i = new Intent(getApplicationContext(),aboutus.class);
startActivity(i);
Try this ..
Button aboutus=(Button) findViewById(R.id.aboutus);
aboutus.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
Intent i = new Intent(getApplicationContext(),aboutus.class);
startActivity(i);
}
});
First, you should make sure that you have declared the aboutus acitivity in your AndroidManifest.xml file.
<Activity android:name= "aboutus"/>
Second, you can use
Intent i = new Intent(getApplicationContext(),aboutus.class);
or
Intent i = new Intent(MainActivity.this,aboutus.class);
instead of
Intent i = new Intent(v.getContext(),aboutus.class);
Intent i = new Intent(v.getContext(),aboutus.class);
startActivity(i);
instead of code use following code and instruction:
Intent i = new Intent(MainActivity.this,aboutus.class);
startActivity(i);
you have to declare the About us activity on AndroidManifest.xml like this
<Activity android:name= ".aboutus"/>

change White background during app launch

I want to get rid of the white color during the short period when my app is launching but the content isn't displayed, yet.
My main activity is :-
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.kam"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.kam.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
how can replace white background to progress bar ?
Update :-
mainfest.xml :
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.kam"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.kam.StartPoint"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.example.kam.MainActivity"/>
</application>
</manifest>
splash.xml
<?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/imageView1"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:src="#drawable/loading" />
<ProgressBar
android:id="#+id/progressBar1"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1.67" />
</LinearLayout>
startpoint.class
public class StartPoint extends Activity{
ProgressBar progressBar;
private int progressBarStatus = 0;
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
progressBar = (ProgressBar)findViewById(R.id.progressBar1);
Thread timer = new Thread(){
public void run(){
try{
sleep(5000);
while(progressBarStatus < 5000){
StartPoint.this.runOnUiThread(new Runnable(){
public void run()
{
progressBar.setProgress(progressBarStatus);
progressBarStatus += 1000;
}
});
}
}catch(InterruptedException e){
e.printStackTrace();
}finally{
Intent openMainList = new Intent(StartPoint.this, com.example.kam.MainActivity.class);
startActivity(openMainList);
}
}
};
timer.start();
}
protected void onPause(){
super.onPause();
finish();
}
}
i will try but when open loading image and open main layout its show error
There a many tutorials and videos for creating Splash Screens, which should give you the desired results.
The basic steps are;
Create a splash image in the desired drawables folders.
Create a theme with your image in it
create an activity using the theme, and have that activity start your current main activity

i cannot see my custom progress dialog

I tried the following code for creating a custom progress dialog. But I am not getting the desired output.
Following is my MainActivity.java code
public class MainActivity extends Activity {
private ProgressDialog mProgressDialog;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
#Override
protected Dialog onCreateDialog(int id) {
mProgressDialog = new ProgressDialog(MainActivity.this);
mProgressDialog.setIcon(R.drawable.alert_dialog_icon);
mProgressDialog.setTitle(R.string.select_dialog);
mProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
return mProgressDialog;
} }
The strings.xml file as follows:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="select_dialog">Sample</string>
<string name="select_dialog_show">List dialog</string>
<string name="app_name">Dialog</string>
</resources>
The activity_main.xml is as follows:
<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=".MainActivity" >
</RelativeLayout>
The DialogManifest.xml is as follows:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.sample.dialog"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="1"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.sample.dialog.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
Hi please refer this URL
When you create an custom view you should give your custom layout to dialog like below
dialog.setContentView(R.layout.maindialog);

Splash in Android not working

I'm trying to create a splash screen for my app in android but it will not show up at all.
The code i'm using is 4 different files. Here it is:
Splash.java
package com.timchecklist;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
public class Splash extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Thread Timer = new Thread() {
public void run() {
try {
sleep(3000);
startActivity(new Intent("com.timchecklist.SPLASHNEW"));
} catch (InterruptedException e) {
e.printStackTrace();
} finally {
finish();
}
}
};
Timer.start();
}
}
SplashNew.java
package com.timchecklist;
import android.app.Activity;
import android.os.Bundle;
import android.view.Window;
public class SplashNew extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.splash);
}
}
Splash.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="#drawable/pic1"
android:gravity="center"
android:orientation="vertical" >
</LinearLayout>
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.timchecklist"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="7" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:name=".TimCheckListActivity"
android:label="#string/app_name"
android:theme="#android:style/Theme.NoTitleBar" >
</activity>
<activity
android:name=".SplashNew"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Please tell me what I'm doing wrong here. Any help would be appreciated. Thanks guys:)
i think Splash should be launcher activity first . and where you declare SPLASHNEW in AndroidManifest File ?.
See Splash Screen Example
You should add SplashNew in Manifest file.
Try below code
setContentView(R.layout.splash);
new Thread(new Runnable() {
public void run() {
// TODO Auto-generated method stub
try {
Thread.sleep(2000);
startActivity(new Intent(getApplicationContext(),EquipmentCategory.class));
finish();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}).start();
There is no entry of SplashNew in menifest file ......
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.timchecklist"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="7" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:name=".TimCheckListActivity"
android:label="#string/app_name" >
</activity>
<activity
android:name=".Splash"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
There is better way to make a splash screen.
Declare an handler like this, which call the next activity to launch after a precised time:
private Handler splashHandler = new Handler() {
#Override
public void handleMessage(Message msg) {
switch (msg.what) {
Intent intent = new Intent(Splash.this, OtherActivity.class);
startActivity(intent);
finish();
break;
}
super.handleMessage(msg);
}
};
Then execute the code after some delay like this in onCreate:
Message msg = new Message();
splashHandler.sendMessageDelayed(msg, SPLASHTIME);

Categories

Resources