Is there any way to restart/shutdown a phone directly from an application?
For Example:
I need to restart/shutdown my Phone when i meet some specific condition...
Citations to Developer Website:
Permission to Reboot?
http://developer.android.com/reference/android/Manifest.permission.html#REBOOT
Permission to Brick the device???
http://developer.android.com/reference/android/Manifest.permission.html#BRICK
Method to reboot???
http://developer.android.com/reference/android/os/PowerManager.html#reboot%28java.lang.String%29
Method to reboot and Wipe??
http://developer.android.com/reference/android/os/RecoverySystem.html#rebootWipeUserData%28android.content.Context%29
Reboot Method in MonkeyRunner/MonkeyDevice:
http://developer.android.com/guide/developing/tools/MonkeyDevice.html#reboot
There are options to brick a device but why not to power-down or restart?
I tried the following code but it throws an exception..
Manifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.schogini.PowerOff"
android:versionCode="1"
android:versionName="1.0">
<uses-permission android:name="android.permission.REBOOT" />
<uses-permission android:name="android.permission.MODIFY_PHONE_STATE" />
<uses-permission android:name="android.permission.DEVICE_POWER" />
<application android:icon="#drawable/icon" android:label="#string/app_name">
<activity android:name=".PowerOffActivity"
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>
Java Code:
package com.schogini.PowerOff;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.os.PowerManager;
import android.view.View;
import android.widget.Button;
public class PowerOffActivity extends Activity {
PowerManager pm;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
Button mBuyButton = (Button) findViewById(R.id.button1);
mBuyButton.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
pm.reboot("null");
}
});
}
}
Exception thrown in LogCat:
06-10 17:58:29.001: WARN/dalvikvm(2064): threadid=3: thread exiting with uncaught exception (group=0x4001b160)
06-10 17:58:29.001: ERROR/AndroidRuntime(2064): Uncaught handler: thread main exiting due to uncaught exception
06-10 17:58:29.011: ERROR/AndroidRuntime(2064): java.lang.NoSuchMethodError: android.os.PowerManager.reboot
06-10 17:58:29.011: ERROR/AndroidRuntime(2064): at com.schogini.PowerOff.PowerOffActivity$1.onClick(PowerOffActivity.java:28)
06-10 17:58:29.011: ERROR/AndroidRuntime(2064): at android.view.View.performClick(View.java:2364)
06-10 17:58:29.011: ERROR/AndroidRuntime(2064): at android.view.View.onTouchEvent(View.java:4179)
06-10 17:58:29.011: ERROR/AndroidRuntime(2064): at android.widget.TextView.onTouchEvent(TextView.java:6545)
06-10 17:58:29.011: ERROR/AndroidRuntime(2064): at android.view.View.dispatchTouchEvent(View.java:3709)
06-10 17:58:29.011: ERROR/AndroidRuntime(2064): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
06-10 17:58:29.011: ERROR/AndroidRuntime(2064): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
06-10 17:58:29.011: ERROR/AndroidRuntime(2064): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
06-10 17:58:29.011: ERROR/AndroidRuntime(2064): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
06-10 17:58:29.011: ERROR/AndroidRuntime(2064): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1659)
06-10 17:58:29.011: ERROR/AndroidRuntime(2064): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1107)
06-10 17:58:29.011: ERROR/AndroidRuntime(2064): at android.app.Activity.dispatchTouchEvent(Activity.java:2061)
06-10 17:58:29.011: ERROR/AndroidRuntime(2064): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1643)
06-10 17:58:29.011: ERROR/AndroidRuntime(2064): at android.view.ViewRoot.handleMessage(ViewRoot.java:1691)
06-10 17:58:29.011: ERROR/AndroidRuntime(2064): at android.os.Handler.dispatchMessage(Handler.java:99)
06-10 17:58:29.011: ERROR/AndroidRuntime(2064): at android.os.Looper.loop(Looper.java:123)
06-10 17:58:29.011: ERROR/AndroidRuntime(2064): at android.app.ActivityThread.main(ActivityThread.java:4363)
06-10 17:58:29.011: ERROR/AndroidRuntime(2064): at java.lang.reflect.Method.invokeNative(Native Method)
06-10 17:58:29.011: ERROR/AndroidRuntime(2064): at java.lang.reflect.Method.invoke(Method.java:521)
06-10 17:58:29.011: ERROR/AndroidRuntime(2064): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
06-10 17:58:29.011: ERROR/AndroidRuntime(2064): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
06-10 17:58:29.011: ERROR/AndroidRuntime(2064): at dalvik.system.NativeStart.main(Native Method)
Not a standard Android distribution, no. Suitably rooted phones often have access to su/reboot commands, but for an off-the-shelf, commercially available device, no: there is no way to do it.
you need to sign the application with signapk. jar using the following command:
java -jar signapk.jar platform.x509.pem platform.pk8 .apk .apk
for this you need to download and build android source code and flash it on a device. You can find the signapk.jar in the \out\host\linux-x86\framework directory.
for more details please refer to the following link:
http://groups.google.com/group/Android-DevPhone-Updating/tree/browse_frm/month/2010-04?_done=/group/Android-DevPhone-Updating/browse_frm/month/2010-04?&&pli=1
Related
I have problem with testing my application on device.
I already successfully open the localhost in browser from my device, but when i enter my ip to connect my application with web service it didn't work.
I always get the "unfortunately, [my apps name] has stopped" message.
Anyone who knows about this problem, please help me. I really need help to solve this. thank you very much
logcat - i get it from usb debug on device
06-10 11:31:15.551: D/dalvikvm(14590): Late-enabling CheckJNI
06-10 11:31:15.809: D/TextLayoutCache(14590): Using debug level: 0 - Debug Enabled: 0
06-10 11:31:15.902: D/libEGL(14590): loaded /vendor/lib/egl/libEGL_POWERVR_SGX540_120.so
06-10 11:31:15.910: D/libEGL(14590): loaded /vendor/lib/egl/libGLESv1_CM_POWERVR_SGX540_120.so
06-10 11:31:15.910: D/libEGL(14590): loaded /vendor/lib/egl/libGLESv2_POWERVR_SGX540_120.so
06-10 11:31:16.160: D/OpenGLRenderer(14590): Enabling debug mode 0
06-10 11:31:19.770: D/OpenGLRenderer(14590): Flushing caches (mode 0)
06-10 11:31:22.309: D/OpenGLRenderer(14590): Flushing caches (mode 0)
06-10 11:31:30.848: D/TryLoginCheck(14590): Here
06-10 11:31:30.848: I/System.out(14590): UserNametes
06-10 11:31:30.848: I/System.out(14590): passwordTes12345*
06-10 11:31:30.848: D/Parameters(14590): username=tes&password=Tes12345*
06-10 11:31:30.863: D/AndroidRuntime(14590): Shutting down VM
06-10 11:31:30.863: W/dalvikvm(14590): threadid=1: thread exiting with uncaught exception (group=0x40bd31f8)
06-10 11:31:30.863: E/AndroidRuntime(14590): FATAL EXCEPTION: main
06-10 11:31:30.863: E/AndroidRuntime(14590): android.os.NetworkOnMainThreadException
06-10 11:31:30.863: E/AndroidRuntime(14590): at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1099)
06-10 11:31:30.863: E/AndroidRuntime(14590): at libcore.io.BlockGuardOs.connect(BlockGuardOs.java:84)
06-10 11:31:30.863: E/AndroidRuntime(14590): at libcore.io.IoBridge.connectErrno(IoBridge.java:127)
06-10 11:31:30.863: E/AndroidRuntime(14590): at libcore.io.IoBridge.connect(IoBridge.java:112)
06-10 11:31:30.863: E/AndroidRuntime(14590): at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:192)
06-10 11:31:30.863: E/AndroidRuntime(14590): at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:459)
06-10 11:31:30.863: E/AndroidRuntime(14590): at java.net.Socket.connect(Socket.java:842)
06-10 11:31:30.863: E/AndroidRuntime(14590): at libcore.net.http.HttpConnection.<init>(HttpConnection.java:77)
06-10 11:31:30.863: E/AndroidRuntime(14590): at libcore.net.http.HttpConnection.<init>(HttpConnection.java:50)
06-10 11:31:30.863: E/AndroidRuntime(14590): at libcore.net.http.HttpConnection$Address.connect(HttpConnection.java:351)
06-10 11:31:30.863: E/AndroidRuntime(14590): at libcore.net.http.HttpConnectionPool.get(HttpConnectionPool.java:86)
06-10 11:31:30.863: E/AndroidRuntime(14590): at libcore.net.http.HttpConnection.connect(HttpConnection.java:128)
06-10 11:31:30.863: E/AndroidRuntime(14590): at libcore.net.http.HttpEngine.openSocketConnection(HttpEngine.java:308)
06-10 11:31:30.863: E/AndroidRuntime(14590): at libcore.net.http.HttpEngine.connect(HttpEngine.java:303)
06-10 11:31:30.863: E/AndroidRuntime(14590): at libcore.net.http.HttpEngine.sendSocketRequest(HttpEngine.java:282)
06-10 11:31:30.863: E/AndroidRuntime(14590): at libcore.net.http.HttpEngine.sendRequest(HttpEngine.java:232)
06-10 11:31:30.863: E/AndroidRuntime(14590): at libcore.net.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:80)
06-10 11:31:30.863: E/AndroidRuntime(14590): at libcore.net.http.HttpURLConnectionImpl.getOutputStream(HttpURLConnectionImpl.java:188)
06-10 11:31:30.863: E/AndroidRuntime(14590): at com.karismaelearning.Login.tryLogin(Login.java:128)
06-10 11:31:30.863: E/AndroidRuntime(14590): at com.karismaelearning.Login$3.onClick(Login.java:73)
06-10 11:31:30.863: E/AndroidRuntime(14590): at android.view.View.performClick(View.java:3558)
06-10 11:31:30.863: E/AndroidRuntime(14590): at android.view.View$PerformClick.run(View.java:14157)
06-10 11:31:30.863: E/AndroidRuntime(14590): at android.os.Handler.handleCallback(Handler.java:605)
06-10 11:31:30.863: E/AndroidRuntime(14590): at android.os.Handler.dispatchMessage(Handler.java:92)
06-10 11:31:30.863: E/AndroidRuntime(14590): at android.os.Looper.loop(Looper.java:137)
06-10 11:31:30.863: E/AndroidRuntime(14590): at android.app.ActivityThread.main(ActivityThread.java:4514)
06-10 11:31:30.863: E/AndroidRuntime(14590): at java.lang.reflect.Method.invokeNative(Native Method)
06-10 11:31:30.863: E/AndroidRuntime(14590): at java.lang.reflect.Method.invoke(Method.java:511)
06-10 11:31:30.863: E/AndroidRuntime(14590): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
06-10 11:31:30.863: E/AndroidRuntime(14590): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557)
06-10 11:31:30.863: E/AndroidRuntime(14590): at dalvik.system.NativeStart.main(Native Method)
06-10 11:31:30.918: D/dalvikvm(14590): GC_CONCURRENT freed 237K, 6% free 6863K/7239K, paused 2ms+2ms
you are getting android.os.NetworkOnMainThreadException :
The exception that is thrown when an application attempts to perform a networking operation on its main thread.
This is only thrown for applications targeting the Honeycomb SDK or higher. Applications targeting earlier SDK versions are allowed to do networking on their main event loop threads, but it's heavily discouraged.
do your code this way in side AsyncTask
there is no error in application but when running it in android emulator I get a sorry message saying my application "has stopped unexpectedly. Please try again".I'm new in android and don't know what is wrong. Please help me.
Logcat is as follows:
06-10 16:55:38.587: D/szipinf(460): Initializing inflate state
06-10 16:55:45.569: D/szipinf(460): Initializing inflate state
06-10 16:55:48.497: D/szipinf(460): Initializing inflate state
06-10 16:55:51.207: I/dalvikvm(460): Jit: resizing JitTable from 512 to 1024
06-10 16:55:53.140: D/szipinf(460): Initializing inflate state
06-10 16:56:02.108: D/AndroidRuntime(460): Shutting down VM
06-10 16:56:02.108: W/dalvikvm(460): threadid=1: thread exiting with uncaught exception (group=0x40015560)
06-10 16:56:02.188: E/AndroidRuntime(460): FATAL EXCEPTION: main
06-10 16:56:02.188: E/AndroidRuntime(460): java.lang.RuntimeException: Unable to start activity ComponentInfo{de.uvwxy.footpath/de.uvwxy.footpath.gui.Loader}: java.lang.StringIndexOutOfBoundsException
06-10 16:56:02.188: E/AndroidRuntime(460): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
06-10 16:56:02.188: E/AndroidRuntime(460): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
06-10 16:56:02.188: E/AndroidRuntime(460): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
06-10 16:56:02.188: E/AndroidRuntime(460): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
06-10 16:56:02.188: E/AndroidRuntime(460): at android.os.Handler.dispatchMessage(Handler.java:99)
06-10 16:56:02.188: E/AndroidRuntime(460): at android.os.Looper.loop(Looper.java:123)
06-10 16:56:02.188: E/AndroidRuntime(460): at android.app.ActivityThread.main(ActivityThread.java:3683)
06-10 16:56:02.188: E/AndroidRuntime(460): at java.lang.reflect.Method.invokeNative(Native Method)
06-10 16:56:02.188: E/AndroidRuntime(460): at java.lang.reflect.Method.invoke(Method.java:507)
06-10 16:56:02.188: E/AndroidRuntime(460): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
06-10 16:56:02.188: E/AndroidRuntime(460): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
06-10 16:56:02.188: E/AndroidRuntime(460): at dalvik.system.NativeStart.main(Native Method)
06-10 16:56:02.188: E/AndroidRuntime(460): Caused by: java.lang.StringIndexOutOfBoundsException
06-10 16:56:02.188: E/AndroidRuntime(460): at java.lang.String.substring(String.java:1651)
06-10 16:56:02.188: E/AndroidRuntime(460): at de.uvwxy.footpath.gui.Loader.onCreate(Loader.java:231)
06-10 16:56:02.188: E/AndroidRuntime(460): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
06-10 16:56:02.188: E/AndroidRuntime(460): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
06-10 16:56:02.188: E/AndroidRuntime(460): ... 11 more
06-10 16:56:12.558: I/Process(460): Sending signal. PID: 460 SIG: 9
As you can tell by reading the stack trace, you have a StringIndexOutOfBoundsException, stemming from line 231 of your de.uvwxy.footpath.gui.Loader class, in its onCreate() method.
You're getting a StringIndexOutOfBoundsException in the Loader.java class at line 231. Check the substringing you're doing at that line.
Trying with the facebook sdk and want to try running the sample app profilepicture .Follow all the step of configuration given in the facebook.developer official site .While import of the facebook sdk some error and exclaimation mark came but that thing are solved .But while running the simple app profilepicture some exception are showing on the logcat.here the details of the logcat with classnotfound exception:
06-10 18:06:48.039: I/Process(621): Sending signal. PID: 621 SIG: 9
06-10 18:08:22.509: W/dalvikvm(697): Unable to resolve superclass of Lcom/facebook/samples/profilepicture/ProfilePictureSampleActivity; (59)
06-10 18:08:22.621: W/dalvikvm(697): Link of class 'Lcom/facebook/samples/profilepicture/ProfilePictureSampleActivity;' failed
06-10 18:08:22.621: D/AndroidRuntime(697): Shutting down VM
06-10 18:08:22.640: W/dalvikvm(697): threadid=1: thread exiting with uncaught exception (group=0x409961f8)
06-10 18:08:22.689: E/AndroidRuntime(697): FATAL EXCEPTION: main
06-10 18:08:22.689: E/AndroidRuntime(697): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.facebook.samples.profilepicture/com.facebook.samples.profilepicture.ProfilePictureSampleActivity}: java.lang.ClassNotFoundException: com.facebook.samples.profilepicture.ProfilePictureSampleActivity
06-10 18:08:22.689: E/AndroidRuntime(697): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1879)
06-10 18:08:22.689: E/AndroidRuntime(697): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1980)
06-10 18:08:22.689: E/AndroidRuntime(697): at android.app.ActivityThread.access$600(ActivityThread.java:122)
06-10 18:08:22.689: E/AndroidRuntime(697): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1146)
06-10 18:08:22.689: E/AndroidRuntime(697): at android.os.Handler.dispatchMessage(Handler.java:99)
06-10 18:08:22.689: E/AndroidRuntime(697): at android.os.Looper.loop(Looper.java:137)
06-10 18:08:22.689: E/AndroidRuntime(697): at android.app.ActivityThread.main(ActivityThread.java:4340)
06-10 18:08:22.689: E/AndroidRuntime(697): at java.lang.reflect.Method.invokeNative(Native Method)
06-10 18:08:22.689: E/AndroidRuntime(697): at java.lang.reflect.Method.invoke(Method.java:511)
06-10 18:08:22.689: E/AndroidRuntime(697): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
06-10 18:08:22.689: E/AndroidRuntime(697): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
06-10 18:08:22.689: E/AndroidRuntime(697): at dalvik.system.NativeStart.main(Native Method)
06-10 18:08:22.689: E/AndroidRuntime(697): Caused by: java.lang.ClassNotFoundException: com.facebook.samples.profilepicture.ProfilePictureSampleActivity
06-10 18:08:22.689: E/AndroidRuntime(697): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
06-10 18:08:22.689: E/AndroidRuntime(697): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
06-10 18:08:22.689: E/AndroidRuntime(697): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
06-10 18:08:22.689: E/AndroidRuntime(697): at android.app.Instrumentation.newActivity(Instrumentation.java:1023)
06-10 18:08:22.689: E/AndroidRuntime(697): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1870)
06-10 18:08:22.689: E/AndroidRuntime(697): ... 11 more
so can anyone tell me what will be the solution for this exception.and this exception is coming for every sample app which came with the facebook sdk.Thanks for any hint.
I'm going through the documentation at Hello, MapView to add a MapView to my Activity.
When I launch my Activity, I get an inflation error on the MapView.
Here is the MapView in my layout xml:
<com.google.android.maps.MapView
android:id="#+id/mymap"
android:layout_width="fill_parent"
android:layout_height="200dip"
android:clickable="true"
android:apiKey="withheld"
/>
Here is the code in my MapActivity (the class is named ActivityDetails and extends MapActivity) class:
MapView mMap;
mMap = (MapView) findViewById(R.id.mymap);
mMap.setBuiltInZoomControls(true);
Here is the error:
06-10 09:15:24.277: ERROR/AndroidRuntime(228): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.my.app/com.my.app.activity.ActivityDetails}: android.view.InflateException: Binary XML file line #35: Error inflating class com.google.android.maps.MapView
06-10 09:15:24.277: ERROR/AndroidRuntime(228): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2496)
06-10 09:15:24.277: ERROR/AndroidRuntime(228): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
06-10 09:15:24.277: ERROR/AndroidRuntime(228): at android.app.ActivityThread.access$2200(ActivityThread.java:119)
06-10 09:15:24.277: ERROR/AndroidRuntime(228): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
06-10 09:15:24.277: ERROR/AndroidRuntime(228): at android.os.Handler.dispatchMessage(Handler.java:99)
06-10 09:15:24.277: ERROR/AndroidRuntime(228): at android.os.Looper.loop(Looper.java:123)
06-10 09:15:24.277: ERROR/AndroidRuntime(228): at android.app.ActivityThread.main(ActivityThread.java:4363)
06-10 09:15:24.277: ERROR/AndroidRuntime(228): at java.lang.reflect.Method.invokeNative(Native Method)
06-10 09:15:24.277: ERROR/AndroidRuntime(228): at java.lang.reflect.Method.invoke(Method.java:521)
06-10 09:15:24.277: ERROR/AndroidRuntime(228): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
06-10 09:15:24.277: ERROR/AndroidRuntime(228): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
06-10 09:15:24.277: ERROR/AndroidRuntime(228): at dalvik.system.NativeStart.main(Native Method)
06-10 09:15:24.277: ERROR/AndroidRuntime(228): Caused by: android.view.InflateException: Binary XML file line #35: Error inflating class com.google.android.maps.MapView
06-10 09:15:24.277: ERROR/AndroidRuntime(228): at android.view.LayoutInflater.createView(LayoutInflater.java:513)
06-10 09:15:24.277: ERROR/AndroidRuntime(228): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:565)
06-10 09:15:24.277: ERROR/AndroidRuntime(228): at android.view.LayoutInflater.rInflate(LayoutInflater.java:618)
06-10 09:15:24.277: ERROR/AndroidRuntime(228): at android.view.LayoutInflater.rInflate(LayoutInflater.java:621)
06-10 09:15:24.277: ERROR/AndroidRuntime(228): at android.view.LayoutInflater.rInflate(LayoutInflater.java:621)
06-10 09:15:24.277: ERROR/AndroidRuntime(228): at android.view.LayoutInflater.inflate(LayoutInflater.java:407)
06-10 09:15:24.277: ERROR/AndroidRuntime(228): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
06-10 09:15:24.277: ERROR/AndroidRuntime(228): at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
06-10 09:15:24.277: ERROR/AndroidRuntime(228): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:198)
06-10 09:15:24.277: ERROR/AndroidRuntime(228): at android.app.Activity.setContentView(Activity.java:1622)
06-10 09:15:24.277: ERROR/AndroidRuntime(228): at com.my.app.activity.ActivityDetails.onCreate(ActivityDetails.java:128)
06-10 09:15:24.277: ERROR/AndroidRuntime(228): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
06-10 09:15:24.277: ERROR/AndroidRuntime(228): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2459)
06-10 09:15:24.277: ERROR/AndroidRuntime(228): ... 11 more
06-10 09:15:24.277: ERROR/AndroidRuntime(228): Caused by: java.lang.reflect.InvocationTargetException
06-10 09:15:24.277: ERROR/AndroidRuntime(228): at com.google.android.maps.MapView.<init>(MapView.java:237)
06-10 09:15:24.277: ERROR/AndroidRuntime(228): at java.lang.reflect.Constructor.constructNative(Native Method)
06-10 09:15:24.277: ERROR/AndroidRuntime(228): at java.lang.reflect.Constructor.newInstance(Constructor.java:446)
06-10 09:15:24.277: ERROR/AndroidRuntime(228): at android.view.LayoutInflater.createView(LayoutInflater.java:500)
06-10 09:15:24.277: ERROR/AndroidRuntime(228): ... 23 more
06-10 09:15:24.277: ERROR/AndroidRuntime(228): Caused by: java.lang.NullPointerException
06-10 09:15:24.277: ERROR/AndroidRuntime(228): at com.google.android.maps.MapActivity.setupMapView(MapActivity.java:183)
06-10 09:15:24.277: ERROR/AndroidRuntime(228): at com.google.android.maps.MapView.<init>(MapView.java:279)
06-10 09:15:24.277: ERROR/AndroidRuntime(228): at com.google.android.maps.MapView.<init>(MapView.java:254)
06-10 09:15:24.277: ERROR/AndroidRuntime(228): ... 27 more
As far as I can tell, I've done everything correct as described in the documentation. I've set my build target to Google APIs, I've added the uses-library tag to my Manifest, I'm running in an emulator with the Google API target...
The problem was I was calling super.onCreate() after setContentView() in the MapActivity.
You are using the wrong xml for your MapView
The class extending the MapActivity should call setContentView() with the xml containing stuff like this
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<com.google.android.maps.MapView
android:id="#+id/racemap"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_x="0px"
android:enabled="true"
android:clickable="true"
android:apiKey="blahblahblah" />
</LinearLayout>
So instead of using layout_details.xml use layout.xml
Insert this on your xml declaration of the MapView
xmlns:android="http://schemas.android.com/apk/res/android"
If I physically slide out the keyboard on my Moto Droid A855, it crashes my test app with the stack trace pasted below. I don't understand why?
Also, if I start my app with the keyboard out, my app crashes immediately on startup.
The app consists of an activity, which contains a viewflipper as the main view layout. The viewflipper contains two linearlayouts...
Stack trace:
06-10 21:10:17.652 E/AndroidRuntime( 3785): Uncaught handler: thread main exiting due to uncaught exception
06-10 21:10:17.668 E/AndroidRuntime( 3785): java.lang.IllegalArgumentException: Receiver not registered: android.widget.ViewFlipper$1#447af0b8
06-10 21:10:17.668 E/AndroidRuntime( 3785): at android.app.ActivityThread$PackageInfo.forgetReceiverDispatcher(ActivityThread.java:667)
06-10 21:10:17.668 E/AndroidRuntime( 3785): at android.app.ApplicationContext.unregisterReceiver(ApplicationContext.java:747)
06-10 21:10:17.668 E/AndroidRuntime( 3785): at android.content.ContextWrapper.unregisterReceiver(ContextWrapper.java:321)
06-10 21:10:17.668 E/AndroidRuntime( 3785): at android.widget.ViewFlipper.onDetachedFromWindow(ViewFlipper.java:104)
06-10 21:10:17.668 E/AndroidRuntime( 3785): at android.view.View.dispatchDetachedFromWindow(View.java:5835)
06-10 21:10:17.668 E/AndroidRuntime( 3785): at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:1076)
06-10 21:10:17.668 E/AndroidRuntime( 3785): at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:1074)
06-10 21:10:17.668 E/AndroidRuntime( 3785): at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:1074)
06-10 21:10:17.668 E/AndroidRuntime( 3785): at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:1074)
06-10 21:10:17.668 E/AndroidRuntime( 3785): at android.view.ViewRoot.dispatchDetachedFromWindow(ViewRoot.java:1570)
06-10 21:10:17.668 E/AndroidRuntime( 3785): at android.view.ViewRoot.doDie(ViewRoot.java:2556)
06-10 21:10:17.668 E/AndroidRuntime( 3785): at android.view.ViewRoot.die(ViewRoot.java:2526)
06-10 21:10:17.668 E/AndroidRuntime( 3785): at android.view.WindowManagerImpl.removeViewImmediate(WindowManagerImpl.java:218)
06-10 21:10:17.668 E/AndroidRuntime( 3785): at android.view.Window$LocalWindowManager.removeViewImmediate(Window.java:436)
06-10 21:10:17.668 E/AndroidRuntime( 3785): at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:3498)
06-10 21:10:17.668 E/AndroidRuntime( 3785): at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:3599)
06-10 21:10:17.668 E/AndroidRuntime( 3785): at android.app.ActivityThread.access$2300(ActivityThread.java:119)
06-10 21:10:17.668 E/AndroidRuntime( 3785): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1867)
06-10 21:10:17.668 E/AndroidRuntime( 3785): at android.os.Handler.dispatchMessage(Handler.java:99)
06-10 21:10:17.668 E/AndroidRuntime( 3785): at android.os.Looper.loop(Looper.java:123)
06-10 21:10:17.668 E/AndroidRuntime( 3785): at android.app.ActivityThread.main(ActivityThread.java:4363)
06-10 21:10:17.668 E/AndroidRuntime( 3785): at java.lang.reflect.Method.invokeNative(Native Method)
06-10 21:10:17.668 E/AndroidRuntime( 3785): at java.lang.reflect.Method.invoke(Method.java:521)
06-10 21:10:17.668 E/AndroidRuntime( 3785): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
06-10 21:10:17.668 E/AndroidRuntime( 3785): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
06-10 21:10:17.668 E/AndroidRuntime( 3785): at dalvik.system.NativeStart.main(Native Method)
06-10 21:10:17.684 I/Process ( 1017): Sending signal. PID: 3785 SIG: 3
EDIT: added XML layout and relevant snippets from main activity.
Entire XML layout file
<?xml version="1.0" encoding="utf-8"?>
<ViewFlipper
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/vFlipper"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<!-- Linear Layout 1: messages and overview. -->
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TableRow android:id="#+id/TableRow01" android:layout_width="fill_parent" android:layout_height="wrap_content">
<TextView
android:text="Connection info"
android:id="#+id/tvCon1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#F0F0F0"
android:textColor="#FF0000"
/>
</TableRow>
<ScrollView
android:id="#+id/ScrollView01"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="#+id/tvMessages"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text=""
/>
</ScrollView>
</LinearLayout>
<!-- Linear Layout 2: settings -->
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TableRow
android:id="#+id/TableRow03"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:text="hello world"
android:id="#+id/asdfasdf2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</TableRow>
</LinearLayout>
</ViewFlipper>
Code snippets from Main Activity:
/**
* Attempt (not currently working) to work around this bug: http://code.google.com/p/android/issues/detail?id=6191
* TODO: make it work.
*/
#Override
public void onDetachedFromWindow() {
Log.d("Dash","OnDetachedFromWindow()");
try {
super.onDetachedFromWindow();
}
catch (Exception e) {
ViewFlipper v = (ViewFlipper)findViewById(R.id.vFlipper);
if (v != null) {
Log.d("Dash","De-Bug hit. e=" + e.getMessage());
v.stopFlipping();
}
}
}
To resolve this issue you must
Define a new class called MyViewFlipper which overrides ViewFlipper (see below)
Reference that new class anywhere you would have previously referenced ViewFlipper
Define your class and layout as shown below:
New class called MyViewFlipper. Contains the following:
package com.gtosoft.dash; // change this to match your own app.
import android.content.Context;
import android.util.AttributeSet;
import android.util.Log;
import android.widget.ViewFlipper;
public class MyViewFlipper extends ViewFlipper {
public MyViewFlipper(Context context, AttributeSet attrs) {
super(context, attrs);
}
#Override
protected void onDetachedFromWindow() {
try{
super.onDetachedFromWindow();
}catch(Exception e) {
Log.d("MyViewFlipper","Stopped a viewflipper crash");
stopFlipping();
}
}
}
Now to use this "fixed" version of ViewFlipper you have to reference it in the xml layout. Since it is basically a "custom view", you have to fully qualify the package path to MyViewFlipper, as seen here:
<com.gtosoft.dash.MyViewFlipper
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/vFlipper"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
(insert all the other old layout code here)
</com.gtosoft.dash.MyViewFlipper>
Now the app no longer crashes on the keyboard slide event or if the app is started with slide already out. Look for this in the log:
06-11 20:08:15.811 D/MyViewFlipper( 6106): Stopped a viewflipper crash
Credit: http://code.google.com/p/android/issues/detail?id=6191
It's really difficult to help you if you don't provide some part of your code... anyway, this error is not new and there are some workarounds in order to solve it (I guess is some bug)... try to do this:
#Override
protected void onDetachedFromWindow() {
try {
super.onDetachedFromWindow();
}
catch (IllegalArgumentException e) {
stopFlipping();
}
}
This is for overriding the onDetachedFromWindow and I hope it works for you.
I know this question was asked almost two years ago, but since then a very easy fix has been implemented. Just add android:configChanges="orientation|keyboard|keyboardHidden" into each Activity call in the Manifest.
yeah I don't see this bug before.. but then again I have this in my manifest
<activity
android:name=".MainActivity"
android:configChanges="keyboardHidden|navigation"
android:label="#string/app_name"
android:launchMode="singleTop" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>