So this is probably an easy thing that I’m trying to do but I’m trying to get the default android loading screen to show and have the text instead say “Consuming…” I’m doing this based off the tutorial in the Android Cookbook. Here are my code and xml files. If you need any other bits of code, just let me know. I honestly am probably doing something stupid but I just need to know. There is nothing happening in logcat so I’m sure what the issue is. Though, the book may just be outdated. I should also note that I’m running of Android 2.2 and I’m testing on a Samsung Galaxy 4G.
So I guess a bit more info is needed. I’m trying to follow the Handling a Time-Consuming Initialization recipe in the Android Developer’s Cookbook: http://bit.ly/sFoBn6
I just want a simple text splash screen. Not even a progress bar. We’re talking simple stupid right now. I’m still learning Android. I just want it to do the normal “Loading..” but instead have it say “Consuming…”
HandleMessage.java
package com.cookbook.handle_message;
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.widget.TextView;
public class HandleMessage extends Activity implements Runnable {
/** Called when the activity is first created. */
TextView mTestLabel;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mTestLabel = (TextView) findViewById(R.id.test);
Thread thread = new Thread(this);
thread.start();
}
private Handler mHandler = new Handler() {
public void handleMessage(Message msg) {
setContentView(R.layout.main);
}
};
public void run() {
initializeArrays();
mHandler.sendEmptyMessage(0);
}
final static int NUM_SAMPS = 1000;
static double[][] correlation;
void initializeArrays() {
if(correlation!=null) return;
correlation = new double[NUM_SAMPS][NUM_SAMPS];
for(int k=0; k<NUM_SAMPS; k++){
for(int m=0; m<NUM_SAMPS; m++){
correlation[k][m] = Math.cos(2*Math.PI*(k+m)/1000);
}
}
}
}
res/layout/main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/test"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />
</LinearLayout>
res/layout/loading.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView android:id="@+id/loading"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Consuming..."/>
</LinearLayout>
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.cookbook.handle_message"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="8" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:label="@string/app_name"
android:name=".HandleMessage" >
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Maybe you just want a progress indicator or something? See this page for an example that shows how to start an activity with a long running thread that updates the progress bar as it goes along.
Also, you indicated LogCat says nothing. Put some Log.i statements in your code to see what’s going on.
EDIT: Ok, in your code above, don’t use 2 layouts. Use just 1. Then in your handler change the text of the textview.
So if you use loading.xml, set that in onCreate and then in your handler just do something like:
Get it? Definitely don’t call setContentView twice for this kind of thing. There may be a way to do that, so maybe it has its uses, but I’ve never done it. Also, as a side note, I’ve started using AsyncTask instead of threads and Handlers for some stuff.
Also, whenever something isn’t working, please add Log statements so that you can tell what’s going on.