Index: android/src/org/rockbox/RockboxActivity.java
===================================================================
--- android/src/org/rockbox/RockboxActivity.java	(revision 27760)
+++ android/src/org/rockbox/RockboxActivity.java	(working copy)
@@ -30,14 +30,10 @@
 import android.view.WindowManager;
 
 public class RockboxActivity extends Activity {
-    /** Called when the activity is first created. */
-    @Override
-    public void onCreate(Bundle savedInstanceState) 
-    {
-        super.onCreate(savedInstanceState);
-        requestWindowFeature(Window.FEATURE_NO_TITLE);
-        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN
-                       ,WindowManager.LayoutParams.FLAG_FULLSCREEN);
+	RockboxUpdater updater = null;
+	
+	public void startService()
+	{
         final Intent intent = new Intent(this, 
                 RockboxService.class);
         startService(intent);
@@ -70,12 +66,26 @@
 				});
         	}
         }).start();
+	}
+    /** Called when the activity is first created. */
+    @Override
+    public void onCreate(Bundle savedInstanceState) 
+    {
+        super.onCreate(savedInstanceState);
+    	if (RockboxService.fb == null)
+    	{
+	        requestWindowFeature(Window.FEATURE_NO_TITLE);
+	        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN
+	                       ,WindowManager.LayoutParams.FLAG_FULLSCREEN);
+	        updater = new RockboxUpdater(this);
+
+	        updater.CheckForUpdate();
+    	}
     }
     
     public void onResume()
     {
     	super.onResume();
-    	
     	if (RockboxService.fb != null)
     	{
     		try {
@@ -97,22 +107,31 @@
     @Override
     protected void onPause() {
     	super.onPause();
-    	RockboxService.fb.suspend();
+    	if (RockboxService.fb != null)
+    	{
+    		RockboxService.fb.suspend();
+    	}
     }
     
     @Override
     protected void onStop() {
     	super.onStop();
-    	RockboxService.fb.suspend();
+    	if (RockboxService.fb != null)
+    	{
+    		RockboxService.fb.suspend();
+    	}
     }
     
     @Override
     protected void onDestroy() {
     	super.onDestroy();
-    	RockboxService.fb.suspend();
+    	if (RockboxService.fb != null)
+    	{
+    		RockboxService.fb.suspend();
+    	}
     }
 
-	private void LOG(CharSequence text)
+	void LOG(CharSequence text)
 	{
 		Log.d("Rockbox", (String) text);
 	}
Index: android/src/org/rockbox/RockboxService.java
===================================================================
--- android/src/org/rockbox/RockboxService.java	(revision 27760)
+++ android/src/org/rockbox/RockboxService.java	(working copy)
@@ -3,19 +3,23 @@
 import java.io.BufferedInputStream;
 import java.io.BufferedOutputStream;
 import java.io.File;
+import java.io.FileInputStream;
 import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
+import java.nio.channels.FileChannel;
 import java.util.Enumeration;
 import java.util.zip.ZipEntry;
 import java.util.zip.ZipFile;
 
+import android.app.AlertDialog;
 import android.app.Notification;
 import android.app.NotificationManager;
 import android.app.PendingIntent;
 import android.app.Service;
+import android.content.DialogInterface;
 import android.content.Intent;
 import android.os.IBinder;
 import android.util.Log;
@@ -83,66 +87,8 @@
 	private void startservice() 
 	{
         fb = new RockboxFramebuffer(this);
-		final int BUFFER = 2048;
-		/* the following block unzips libmisc.so, which contains the files 
-		 * we ship, such as themes. It's needed to put it into a .so file
-		 * because there's no other way to ship files and have access
-		 * to them from native code
-		 */
-		try
-		{
-           BufferedOutputStream dest = null;
-           BufferedInputStream is = null;
-           ZipEntry entry;
-           File file = new File("/data/data/org.rockbox/lib/libmisc.so");
-           /* use arbitary file to determine whether extracting is needed */
-           File file2 = new File("/data/data/org.rockbox/app_rockbox/rockbox/codecs/mpa.codec");
-           if (!file2.exists() || (file.lastModified() > file2.lastModified()))
-           {
-	           ZipFile zipfile = new ZipFile(file);
-	           Enumeration<? extends ZipEntry> e = zipfile.entries();
-	           File folder;
-	           while(e.hasMoreElements()) {
-	              entry = (ZipEntry) e.nextElement();
-	              LOG("Extracting: " +entry);
-	              if (entry.isDirectory())
-	              {
-	            	  folder = new File(entry.getName());
-	            	  LOG("mkdir "+ entry);
-	            	  try {
-	            		  folder.mkdirs();
-	            	  } catch (SecurityException ex){
-	            		  LOG(ex.getMessage());
-	            	  }
-	            	  continue;
-	              }
-	              is = new BufferedInputStream(zipfile.getInputStream(entry));
-	              int count;
-	              byte data[] = new byte[BUFFER];
-	              folder = new File(new File(entry.getName()).getParent());
-	              LOG("" + folder.getAbsolutePath());
-	              if (!folder.exists())
-	            	  folder.mkdirs();
-	              FileOutputStream fos = new FileOutputStream(entry.getName());
-	              dest = new BufferedOutputStream(fos, BUFFER);
-	              while ((count = is.read(data, 0, BUFFER)) != -1) {
-	                 dest.write(data, 0, count);
-	              }
-	              dest.flush();
-	              dest.close();
-	              is.close();
-	           }
-           }
-        } catch(FileNotFoundException e) {
-        	LOG("FileNotFoundException when unzipping", e);
-        	e.printStackTrace();
-        } catch(IOException e) {
-        	LOG("IOException when unzipping", e);
-        	e.printStackTrace();
-        }
-
         System.loadLibrary("rockbox");
-
+        
     	Thread rb = new Thread(new Runnable()
     	{
     		public void run()
@@ -153,7 +99,7 @@
     	rb.setDaemon(false);
     	rb.start();
 	}
-
+	
     private native void main();
 	@Override
 	public IBinder onBind(Intent intent) {
Index: android/src/org/rockbox/RockboxUpdater.java
===================================================================
--- android/src/org/rockbox/RockboxUpdater.java	(revision 0)
+++ android/src/org/rockbox/RockboxUpdater.java	(revision 0)
@@ -0,0 +1,107 @@
+package org.rockbox;
+
+import java.io.BufferedInputStream;
+import java.io.BufferedOutputStream;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.Enumeration;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipException;
+import java.util.zip.ZipFile;
+
+import android.app.Activity;
+import android.app.AlertDialog;
+import android.content.DialogInterface;
+
+public class RockboxUpdater {
+	private final String zipfile = "/sdcard/rockbox/rockbox.zip";
+	private final String librockbox = "/data/data/org.rockbox/app_rockbox/rockbox/librockbox.so";
+	private RockboxActivity myActivity = null;
+	public RockboxUpdater(RockboxActivity activity) {
+		myActivity = activity;
+	}
+	
+	public void CheckForUpdate() {
+		File file = new File(zipfile);
+        File file2 = new File(librockbox);
+        String message = null;
+        if (!file.exists() && !file2.exists()) {
+        	message = "Do you want to download the ROCKbox application data?";
+        }
+        else if (file.exists() && (file.lastModified() > file2.lastModified())) {
+        	message = "ROCKbox update found, install it?";
+        }
+        if (message != null) {
+     	    AlertDialog alert = new AlertDialog.Builder(myActivity).create();
+     	    alert.setTitle("ROCKbox Installer");
+     	    alert.setMessage(message);
+     	    alert.setButton(AlertDialog.BUTTON_POSITIVE, "Yes", new DialogInterface.OnClickListener() {
+     	    	public void onClick(DialogInterface dialog, int which) {
+     	    		if (!new File(zipfile).exists()){
+         	    		/* Do the download here */
+         		    	myActivity.finish();
+     	    		}
+     	    		doUpdate();
+     	    		myActivity.startService();
+     		    }
+     	    });
+     	    alert.setButton(AlertDialog.BUTTON_NEGATIVE, "No", new DialogInterface.OnClickListener() {
+     		    public void onClick(DialogInterface dialog, int which) {
+     		    	myActivity.finish();
+     		    }
+     	    });
+     	    alert.show();
+        } else {
+        	myActivity.startService();
+        }
+	}
+	
+	private void doUpdate() {
+		final int BUFFER = 2048;
+        BufferedOutputStream dest = null;
+        BufferedInputStream is = null;
+        ZipEntry entry;
+        try {
+			File file = new File(zipfile);
+	        ZipFile zipfile;
+			zipfile = new ZipFile(file);
+	        Enumeration<? extends ZipEntry> e = zipfile.entries();
+	        File folder;
+	        while(e.hasMoreElements()) {
+	        	entry = (ZipEntry) e.nextElement();
+	            myActivity.LOG("Extracting: " +entry);
+	            if (entry.isDirectory())
+	            {
+	            	folder = new File(entry.getName());
+	         	    myActivity.LOG("mkdir "+ entry);
+	         	    try {
+	         	    	folder.mkdirs();
+	         	    } catch (SecurityException ex){
+	         	    	myActivity.LOG(ex.getMessage());
+	         	    }
+	         	    continue;
+	            }
+	            is = new BufferedInputStream(zipfile.getInputStream(entry));
+	            int count;
+	            byte data[] = new byte[BUFFER];
+	            folder = new File(new File(entry.getName()).getParent());
+	            myActivity.LOG("" + folder.getAbsolutePath());
+	            if (!folder.exists())
+	            	folder.mkdirs();
+	            FileOutputStream fos = new FileOutputStream(entry.getName());
+	            dest = new BufferedOutputStream(fos, BUFFER);
+	            while ((count = is.read(data, 0, BUFFER)) != -1) {
+	                dest.write(data, 0, count);
+	            }
+	            dest.flush();
+	            dest.close();
+	            is.close();		
+	        }
+		}
+        catch (Exception e)
+        {
+        }
+	}
+	
+}
Index: tools/buildzip.pl
===================================================================
--- tools/buildzip.pl	(revision 27760)
+++ tools/buildzip.pl	(working copy)
@@ -620,9 +620,17 @@
         # Don't include image file in fonts-only package
         undef $target;
     }
+    
+    unless (".rockbox" eq $rbdir) {
+        mkpath($rbdir);
+        rmtree($rbdir);
+        move(".rockbox", $rbdir);
+        print "mv .rockbox $rbdir\n" if $verbose;
+    }
     if($target && ($target !~ /(mod|ajz|wma)\z/i)) {
         # On some targets, the image goes into .rockbox.
         copy("$target", "$rbdir/$target");
+        print "copy $target $rbdir/$target\n" if $verbose;
         undef $target;
     }
 
@@ -630,16 +638,10 @@
         make_install(".rockbox", $install) or die "MKDIRFAILED\n";
     }
     else {
-        unless (".rockbox" eq $rbdir) {
-            mkpath($rbdir);
-            rmtree($rbdir);
-            move(".rockbox", $rbdir);
-            print "mv .rockbox $rbdir\n" if $verbose;
-        }
         system("$ziptool $output $rbdir $target >/dev/null");
         print "$ziptool $output $rbdir $target >/dev/null\n" if $verbose;
     }
-    rmtree(".rockbox");
+    #rmtree(".rockbox");
     print "rm .rockbox\n" if $verbose;
 };
 
