How to display an image in an image button with shared preferences? - android

In one of my activities you can click on an image button and a dialog opens up to ask you to open up the Gallery. Once opened up you can click on one of those images in your gallery.
What I want that the clicked image is set as the image of the image button. This image should stay there even when the user kills the app (when he opens up the app again the chosen image should still be there).
I chose to do all this work with the shared preferences but can't get it working. I get an error when I click on an image in the gallery. Any suggestions??
UPDATE: The error I receive is:
Unfortunately, the process com.myname.android has stopped
Here is my code, beginning with the onActivityResult:
private String selectedImagePath;
private String mFileName;
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK) {
if (requestCode == PICK_FROM_FILE) {
Uri selectedImageUri = data.getData();
selectedImagePath = getPath(selectedImageUri);
Log.v("IMAGE PATH====>>>> ",selectedImagePath);
}
storePath();
retrievePath();
convertPathToImage();
}
}
private void storePath() {
final SharedPreferences sPreference = getSharedPreferences(
"pref_key", MODE_PRIVATE);
final Editor spEditor = sPreference.edit();
spEditor.putString("img_path", mFileName);
spEditor.commit();
}
private void retrievePath() {
final SharedPreferences sharedPreference = getSharedPreferences(
"pref_key", MODE_PRIVATE);
if (sharedPreference.contains("img_path")) {
mFileName = sharedPreference.getString("img_path",
null);
}
}
private void convertPathToImage() {
File imgFile = new File(mFileName);
if(imgFile.exists()){
Bitmap myBitmap = BitmapFactory.decodeFile(imgFile.getAbsolutePath());
ImageButton myImage = (ImageButton) findViewById(R.id.image);
myImage.setImageBitmap(myBitmap);
}
}
And here is the LogCat:
05-30 15:27:14.567: D/dalvikvm(634): GC_CONCURRENT freed 1K, 3% free 11478K/11783K, paused 5ms+4ms
05-30 15:27:14.597: I/dalvikvm(634): threadid=3: reacting to signal 3
05-30 15:27:14.617: I/dalvikvm(634): Wrote stack traces to '/data/anr/traces.txt'
05-30 15:27:14.926: D/gralloc_goldfish(634): Emulator without GPU emulation detected.
05-30 15:27:26.767: I/dalvikvm(634): threadid=3: reacting to signal 3
05-30 15:27:26.877: I/dalvikvm(634): Wrote stack traces to '/data/anr/traces.txt'
05-30 15:27:30.616: I/dalvikvm(634): threadid=3: reacting to signal 3
05-30 15:27:30.626: I/dalvikvm(634): Wrote stack traces to '/data/anr/traces.txt'
05-30 15:27:32.086: W/IInputConnectionWrapper(634): showStatusIcon on inactive InputConnection
05-30 15:27:33.366: E/ActivityThread(634): Activity com.android.internal.app.ChooserActivity has leaked IntentReceiver com.android.internal.app.ResolverActivity$1#4155da80 that was originally registered here. Are you missing a call to unregisterReceiver()?
05-30 15:27:33.366: E/ActivityThread(634): android.app.IntentReceiverLeaked: Activity com.android.internal.app.ChooserActivity has leaked IntentReceiver com.android.internal.app.ResolverActivity$1#4155da80 that was originally registered here. Are you missing a call to unregisterReceiver()?
05-30 15:27:33.366: E/ActivityThread(634): at android.app.LoadedApk$ReceiverDispatcher.<init>(LoadedApk.java:763)
05-30 15:27:33.366: E/ActivityThread(634): at android.app.LoadedApk.getReceiverDispatcher(LoadedApk.java:567)
05-30 15:27:33.366: E/ActivityThread(634): at android.app.ContextImpl.registerReceiverInternal(ContextImpl.java:1043)
05-30 15:27:33.366: E/ActivityThread(634): at android.app.ContextImpl.registerReceiver(ContextImpl.java:1030)
05-30 15:27:33.366: E/ActivityThread(634): at android.app.ContextImpl.registerReceiver(ContextImpl.java:1024)
05-30 15:27:33.366: E/ActivityThread(634): at android.content.ContextWrapper.registerReceiver(ContextWrapper.java:341)
05-30 15:27:33.366: E/ActivityThread(634): at com.android.internal.content.PackageMonitor.register(PackageMonitor.java:65)
05-30 15:27:33.366: E/ActivityThread(634): at com.android.internal.app.ResolverActivity.onCreate(ResolverActivity.java:99)
05-30 15:27:33.366: E/ActivityThread(634): at com.android.internal.app.ChooserActivity.onCreate(ChooserActivity.java:53)
05-30 15:27:33.366: E/ActivityThread(634): at android.app.Activity.performCreate(Activity.java:4465)
05-30 15:27:33.366: E/ActivityThread(634): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
05-30 15:27:33.366: E/ActivityThread(634): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
05-30 15:27:33.366: E/ActivityThread(634): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
05-30 15:27:33.366: E/ActivityThread(634): at android.app.ActivityThread.access$600(ActivityThread.java:123)
05-30 15:27:33.366: E/ActivityThread(634): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
05-30 15:27:33.366: E/ActivityThread(634): at android.os.Handler.dispatchMessage(Handler.java:99)
05-30 15:27:33.366: E/ActivityThread(634): at android.os.Looper.loop(Looper.java:137)
05-30 15:27:33.366: E/ActivityThread(634): at android.app.ActivityThread.main(ActivityThread.java:4424)
05-30 15:27:33.366: E/ActivityThread(634): at java.lang.reflect.Method.invokeNative(Native Method)
05-30 15:27:33.366: E/ActivityThread(634): at java.lang.reflect.Method.invoke(Method.java:511)
05-30 15:27:33.366: E/ActivityThread(634): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
05-30 15:27:33.366: E/ActivityThread(634): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
05-30 15:27:33.366: E/ActivityThread(634): at dalvik.system.NativeStart.main(Native Method)
05-30 15:27:35.987: V/IMAGE PATH====>>>>(634): /mnt/sdcard/Mercedes_SLS_AMG.jpg
05-30 15:27:36.176: D/AndroidRuntime(634): Shutting down VM
05-30 15:27:36.176: W/dalvikvm(634): threadid=1: thread exiting with uncaught exception (group=0x409c01f8)
05-30 15:27:36.206: E/AndroidRuntime(634): FATAL EXCEPTION: main
05-30 15:27:36.206: E/AndroidRuntime(634): java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=0, result=-1, data=Intent { dat=content://media/external/images/media/20 }} to activity {com.xyz.android.taskreminder/com.xyz.android.taskreminder.ReminderEditActivity}: java.lang.NullPointerException
05-30 15:27:36.206: E/AndroidRuntime(634): at android.app.ActivityThread.deliverResults(ActivityThread.java:2980)
05-30 15:27:36.206: E/AndroidRuntime(634): at android.app.ActivityThread.handleSendResult(ActivityThread.java:3023)
05-30 15:27:36.206: E/AndroidRuntime(634): at android.app.ActivityThread.access$1100(ActivityThread.java:123)
05-30 15:27:36.206: E/AndroidRuntime(634): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1177)
05-30 15:27:36.206: E/AndroidRuntime(634): at android.os.Handler.dispatchMessage(Handler.java:99)
05-30 15:27:36.206: E/AndroidRuntime(634): at android.os.Looper.loop(Looper.java:137)
05-30 15:27:36.206: E/AndroidRuntime(634): at android.app.ActivityThread.main(ActivityThread.java:4424)
05-30 15:27:36.206: E/AndroidRuntime(634): at java.lang.reflect.Method.invokeNative(Native Method)
05-30 15:27:36.206: E/AndroidRuntime(634): at java.lang.reflect.Method.invoke(Method.java:511)
05-30 15:27:36.206: E/AndroidRuntime(634): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
05-30 15:27:36.206: E/AndroidRuntime(634): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
05-30 15:27:36.206: E/AndroidRuntime(634): at dalvik.system.NativeStart.main(Native Method)
05-30 15:27:36.206: E/AndroidRuntime(634): Caused by: java.lang.NullPointerException
05-30 15:27:36.206: E/AndroidRuntime(634): at java.io.File.fixSlashes(File.java:185)
05-30 15:27:36.206: E/AndroidRuntime(634): at java.io.File.<init>(File.java:134)
05-30 15:27:36.206: E/AndroidRuntime(634): at com.xyz.android.taskreminder.ReminderEditActivity.convertPathToImage(ReminderEditActivity.java:249)
05-30 15:27:36.206: E/AndroidRuntime(634): at com.xyz.android.taskreminder.ReminderEditActivity.onActivityResult(ReminderEditActivity.java:227)
05-30 15:27:36.206: E/AndroidRuntime(634): at android.app.Activity.dispatchActivityResult(Activity.java:4649)
05-30 15:27:36.206: E/AndroidRuntime(634): at android.app.ActivityThread.deliverResults(ActivityThread.java:2976)
05-30 15:27:36.206: E/AndroidRuntime(634): ... 11 more
05-30 15:27:36.376: I/dalvikvm(634): threadid=3: reacting to signal 3
05-30 15:27:36.396: I/dalvikvm(634): Wrote stack traces to '/data/anr/traces.txt'
05-30 15:27:36.787: I/dalvikvm(634): threadid=3: reacting to signal 3
05-30 15:27:36.847: I/dalvikvm(634): Wrote stack traces to '/data/anr/traces.txt'
05-30 15:27:37.386: I/dalvikvm(634): threadid=3: reacting to signal 3
05-30 15:27:37.406: I/dalvikvm(634): Wrote stack traces to '/data/anr/traces.txt'
05-30 15:27:37.887: I/dalvikvm(634): threadid=3: reacting to signal 3
05-30 15:27:37.947: I/dalvikvm(634): Wrote stack traces to '/data/anr/traces.txt'
05-30 15:27:38.396: I/dalvikvm(634): threadid=3: reacting to signal 3
05-30 15:27:38.416: I/dalvikvm(634): Wrote stack traces to '/data/anr/traces.txt'
05-30 15:27:38.897: I/dalvikvm(634): threadid=3: reacting to signal 3
05-30 15:27:38.927: I/dalvikvm(634): Wrote stack traces to '/data/anr/traces.txt'
05-30 15:27:39.406: I/dalvikvm(634): threadid=3: reacting to signal 3
05-30 15:27:39.426: I/dalvikvm(634): Wrote stack traces to '/data/anr/traces.txt'
05-30 15:27:39.917: I/dalvikvm(634): threadid=3: reacting to signal 3
05-30 15:27:39.927: I/dalvikvm(634): Wrote stack traces to '/data/anr/traces.txt'
05-30 15:27:40.426: I/dalvikvm(634): threadid=3: reacting to signal 3
05-30 15:27:40.446: I/dalvikvm(634): Wrote stack traces to '/data/anr/traces.txt'
05-30 15:27:40.917: I/dalvikvm(634): threadid=3: reacting to signal 3
05-30 15:27:40.947: I/dalvikvm(634): Wrote stack traces to '/data/anr/traces.txt'
05-30 15:27:41.426: I/dalvikvm(634): threadid=3: reacting to signal 3
05-30 15:27:41.447: I/dalvikvm(634): Wrote stack traces to '/data/anr/traces.txt'
05-30 15:27:41.937: I/dalvikvm(634): threadid=3: reacting to signal 3
05-30 15:27:41.977: I/dalvikvm(634): Wrote stack traces to '/data/anr/traces.txt'
05-30 15:27:42.446: I/dalvikvm(634): threadid=3: reacting to signal 3
05-30 15:27:42.467: I/dalvikvm(634): Wrote stack traces to '/data/anr/traces.txt'
05-30 15:27:42.937: I/dalvikvm(634): threadid=3: reacting to signal 3
05-30 15:27:42.956: I/dalvikvm(634): Wrote stack traces to '/data/anr/traces.txt'
05-30 15:27:43.446: I/dalvikvm(634): threadid=3: reacting to signal 3
05-30 15:27:43.467: I/dalvikvm(634): Wrote stack traces to '/data/anr/traces.txt'
05-30 15:27:43.947: I/dalvikvm(634): threadid=3: reacting to signal 3
05-30 15:27:43.976: I/dalvikvm(634): Wrote stack traces to '/data/anr/traces.txt'
05-30 15:27:44.456: I/dalvikvm(634): threadid=3: reacting to signal 3
05-30 15:27:44.477: I/dalvikvm(634): Wrote stack traces to '/data/anr/traces.txt'
05-30 15:27:44.966: I/dalvikvm(634): threadid=3: reacting to signal 3
05-30 15:27:44.986: I/dalvikvm(634): Wrote stack traces to '/data/anr/traces.txt'
05-30 15:27:45.466: I/dalvikvm(634): threadid=3: reacting to signal 3
05-30 15:27:45.487: I/dalvikvm(634): Wrote stack traces to '/data/anr/traces.txt'

Activity com.android.internal.app.ChooserActivity has leaked IntentReceiver com.android.internal.app.ResolverActivity$1#4155da80 that was originally registered here. Are you missing a call to unregisterReceiver()?
This is probably a bug in Android. See http://code.google.com/p/android/issues/detail?id=29399. It shouldn't effect the app though which should still be able to get a result back from the gallery.
05-30 15:27:36.206: E/AndroidRuntime(634): java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=0, result=-1, data=Intent { dat=content://media/external/images/media/20 }} to activity {com.ndroidstudios.android.taskreminder/com.ndroidstudios.android.taskreminder.ReminderEditActivity}: java.lang.NullPointerException
...
05-30 15:27:36.206: E/AndroidRuntime(634): Caused by: java.lang.NullPointerException
This is the problem. mFileName is null when you try to use it to create a new File. In retrievePath, when you try to pull "img_path" out of your preferences the default value is null, so I'm guessing it's getting set to null there. Check in the debugger to make sure mFileName is getting set to a valid String from your preferences.

Related

Clicking links in custom listview

I'm attempting to put together a library for Twitter feeds and I've got most of it working, but I'm running into an issue where links in my text are crashing when clicked, and I wanted to see if anyone could point me in the right direction for fixing this.
The main text field of my tweet is defined in XML as this:
<TextView
android:textColor="#android:color/black"
android:id="#+id/TweetUITweetTextTextView"
android:padding="#dimen/tweetTextPadding"
android:layout_toRightOf="#+id/TweetUIUserProfileImageView"
android:layout_below="#+id/TweetUIUsernameTextView"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:linksClickable="true"
android:autoLink="web"
android:text="#null" />
And this is located inside of a relative layout that I expand into a custom "TweetView" class.
The TweetView takes a Tweet Object that is basically a set of strings that contain the information parsed from a JSON query and sets those strings (In this case, the main text from the Tweet with anchor tags and whatnot from the URL metadata in the Twitter JSON feed) to the textview with this:
if( tweet.tweetText != null && tweet.tweetText != "" )
tweetTextTextView.setText( Html.fromHtml( tweet.tweetTextWithLinks ) );
else
tweetTextTextView.setText( "" );
As for my error stack on crash, I have this:
05-30 14:42:22.206: E/InputEventReceiver(22150): Exception dispatching input event.
05-30 14:42:22.206: E/MessageQueue-JNI(22150): Exception in MessageQueue callback: handleReceiveCallback
05-30 14:42:22.216: E/MessageQueue-JNI(22150): android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?
05-30 14:42:22.216: E/MessageQueue-JNI(22150): at android.app.ContextImpl.startActivity(ContextImpl.java:944)
05-30 14:42:22.216: E/MessageQueue-JNI(22150): at android.app.ContextImpl.startActivity(ContextImpl.java:931)
05-30 14:42:22.216: E/MessageQueue-JNI(22150): at android.content.ContextWrapper.startActivity(ContextWrapper.java:284)
05-30 14:42:22.216: E/MessageQueue-JNI(22150): at android.text.style.URLSpan.onClick(URLSpan.java:62)
05-30 14:42:22.216: E/MessageQueue-JNI(22150): at android.text.method.LinkMovementMethod.onTouchEvent(LinkMovementMethod.java:212)
05-30 14:42:22.216: E/MessageQueue-JNI(22150): at android.widget.TextView.onTouchEvent(TextView.java:7536)
05-30 14:42:22.216: E/MessageQueue-JNI(22150): at android.view.View.dispatchTouchEvent(View.java:7246)
05-30 14:42:22.216: E/MessageQueue-JNI(22150): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2174)
05-30 14:42:22.216: E/MessageQueue-JNI(22150): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1917)
05-30 14:42:22.216: E/MessageQueue-JNI(22150): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2174)
05-30 14:42:22.216: E/MessageQueue-JNI(22150): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1917)
05-30 14:42:22.216: E/MessageQueue-JNI(22150): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2174)
05-30 14:42:22.216: E/MessageQueue-JNI(22150): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1917)
05-30 14:42:22.216: E/MessageQueue-JNI(22150): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2174)
05-30 14:42:22.216: E/MessageQueue-JNI(22150): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1917)
05-30 14:42:22.216: E/MessageQueue-JNI(22150): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2174)
05-30 14:42:22.216: E/MessageQueue-JNI(22150): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1917)
05-30 14:42:22.216: E/MessageQueue-JNI(22150): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2174)
05-30 14:42:22.216: E/MessageQueue-JNI(22150): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1917)
05-30 14:42:22.216: E/MessageQueue-JNI(22150): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2174)
05-30 14:42:22.216: E/MessageQueue-JNI(22150): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1917)
05-30 14:42:22.216: E/MessageQueue-JNI(22150): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1953)
.....
Thank you!
Probably you pass "wrong" context in your adapter. E.g. application context instead of activity context.

Android Socket Client closes itself [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
android.os.NetworkOnMainThreadException
Android Socket Client didn’t send and closes itself
i am new to java and android programming and i am trying to programm an Android Client and a server for my pc (windows 7). With this connection i want to send a string from pc to the android app and also from the app to the pc. I checked my server, whether it is programmed correctly and it is. So i must habe an error in my client. When i launch the app. The app starts but when i want to send a string from my app to the pc the app just closes itself. Now i need your help indeed. I have been programming just on the app for more than 2 days.
Here is my LogCat and i really hope that you can tell me where i can find my mistake.
12-28 21:10:29.348: I/dalvikvm(565): threadid=3: reacting to signal 3
12-28 21:10:29.428: I/dalvikvm(565): Wrote stack traces to '/data/anr/traces.txt'
12-28 21:10:29.818: I/dalvikvm(565): threadid=3: reacting to signal 3
12-28 21:10:29.888: I/dalvikvm(565): Wrote stack traces to '/data/anr/traces.txt'
12-28 21:10:30.258: D/gralloc_goldfish(565): Emulator without GPU emulation detected.
12-28 21:10:30.319: I/dalvikvm(565): threadid=3: reacting to signal 3
12-28 21:10:30.348: I/dalvikvm(565): Wrote stack traces to '/data/anr/traces.txt'
12-28 21:11:12.498: D/AndroidRuntime(565): Shutting down VM
12-28 21:11:12.508: W/dalvikvm(565): threadid=1: thread exiting with uncaught exception
(group=0x409c01f8)
12-28 21:11:12.540: E/AndroidRuntime(565): FATAL EXCEPTION: main
12-28 21:11:12.540: E/AndroidRuntime(565): android.os.NetworkOnMainThreadException
12-28 21:11:12.540: E/AndroidRuntime(565): at
android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1099)
12-28 21:11:12.540: E/AndroidRuntime(565): at
libcore.io.BlockGuardOs.connect(BlockGuardOs.java:84)
12-28 21:11:12.540: E/AndroidRuntime(565): at
libcore.io.IoBridge.connectErrno(IoBridge.java:127)
12-28 21:11:12.540: E/AndroidRuntime(565): at
libcore.io.IoBridge.connect(IoBridge.java:112)
12-28 21:11:12.540: E/AndroidRuntime(565): at
java.net.PlainSocketImpl.connect(PlainSocketImpl.java:192)
12-28 21:11:12.540: E/AndroidRuntime(565): at
java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
12-28 21:11:12.540: E/AndroidRuntime(565): at
java.net.Socket.startupSocket(Socket.java:566)
12-28 21:11:12.540: E/AndroidRuntime(565): at
java.net.Socket.tryAllAddresses(Socket.java:127)
12-28 21:11:12.540: E/AndroidRuntime(565): at java.net.Socket.<init>(Socket.java:177)
12-28 21:11:12.540: E/AndroidRuntime(565): at java.net.Socket.<init>(Socket.java:149)
12-28 21:11:12.540: E/AndroidRuntime(565): at
net.ibasic.AndroidClient$1.onClick(AndroidClient.java:50)
12-28 21:11:12.540: E/AndroidRuntime(565): at
android.view.View.performClick(View.java:3511)
12-28 21:11:12.540: E/AndroidRuntime(565): at
android.view.View$PerformClick.run(View.java:14105)
12-28 21:11:12.540: E/AndroidRuntime(565): at
android.os.Handler.handleCallback(Handler.java:605)
12-28 21:11:12.540: E/AndroidRuntime(565): at
android.os.Handler.dispatchMessage(Handler.java:92)
12-28 21:11:12.540: E/AndroidRuntime(565): at android.os.Looper.loop(Looper.java:137)
12-28 21:11:12.540: E/AndroidRuntime(565): at
android.app.ActivityThread.main(ActivityThread.java:4424)
12-28 21:11:12.540: E/AndroidRuntime(565): at
java.lang.reflect.Method.invokeNative(Native Method)
12-28 21:11:12.540: E/AndroidRuntime(565): at
java.lang.reflect.Method.invoke(Method.java:511)
12-28 21:11:12.540: E/AndroidRuntime(565): at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
12-28 21:11:12.540: E/AndroidRuntime(565): at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
12-28 21:11:12.540: E/AndroidRuntime(565): at dalvik.system.NativeStart.main(Native
Method)
12-28 21:11:13.178: I/dalvikvm(565): threadid=3: reacting to signal 3
12-28 21:11:13.218: I/dalvikvm(565): Wrote stack traces to '/data/anr/traces.txt'
12-28 21:11:15.288: I/Process(565): Sending signal. PID: 565 SIG: 9
It sounds like you probably are doing the network stuff in main UI instead of background like AsyncTask
Here is a basic example of how it is set up
public class MyNetworkTask extends AsyncTask<String, String, String> {
#Override
protected void onPreExecute() {
super.onPreExecute();
}
#Override
protected void onProgressUpdate(String... values) {
super.onProgressUpdate(values);
}
#Override
protected String doInBackground(String... params) {
//do your work here
return something;
}
#Override
protected void onPostExecute(String result) {
super.onPostExecute(result);
// do something with data here-display it or send to mainactivity
}
Here is a link to the documentation for it:
http://developer.android.com/reference/android/os/AsyncTask.html

android parcel read exception

this is the follow up question to this one
I get the following stack logcat parcel read ecception why do I get this
10-09 10:27:27.993: I/dalvikvm(825): threadid=3: reacting to signal 3
10-09 10:27:28.093: I/dalvikvm(825): Wrote stack traces to '/data/anr/traces.txt'
10-09 10:27:28.422: D/gralloc_goldfish(825): Emulator without GPU emulation detected.
10-09 10:28:45.692: W/ActivityThread(872): Application com.example.sms is waiting for the debugger on port 8100...
10-09 10:28:45.793: I/System.out(872): Sending WAIT chunk
10-09 10:28:45.813: I/dalvikvm(872): Debugger is active
10-09 10:28:45.833: I/System.out(872): Debugger has connected
10-09 10:28:45.853: I/System.out(872): waiting for debugger to settle...
10-09 10:28:46.063: I/System.out(872): waiting for debugger to settle...
10-09 10:28:46.263: I/System.out(872): waiting for debugger to settle...
10-09 10:28:46.273: I/dalvikvm(872): threadid=3: reacting to signal 3
10-09 10:28:46.312: I/dalvikvm(872): Wrote stack traces to '/data/anr/traces.txt'
10-09 10:28:46.462: I/System.out(872): waiting for debugger to settle...
10-09 10:28:46.662: I/System.out(872): waiting for debugger to settle...
10-09 10:28:46.783: I/dalvikvm(872): threadid=3: reacting to signal 3
10-09 10:28:46.793: I/dalvikvm(872): Wrote stack traces to '/data/anr/traces.txt'
10-09 10:28:46.863: I/System.out(872): waiting for debugger to settle...
10-09 10:28:47.072: I/System.out(872): waiting for debugger to settle...
10-09 10:28:47.263: I/dalvikvm(872): threadid=3: reacting to signal 3
10-09 10:28:47.293: I/System.out(872): waiting for debugger to settle...
10-09 10:28:47.293: I/dalvikvm(872): Wrote stack traces to '/data/anr/traces.txt'
10-09 10:28:47.492: I/System.out(872): waiting for debugger to settle...
10-09 10:28:47.692: I/System.out(872): waiting for debugger to settle...
10-09 10:28:47.763: I/dalvikvm(872): threadid=3: reacting to signal 3
10-09 10:28:47.773: I/dalvikvm(872): Wrote stack traces to '/data/anr/traces.txt'
10-09 10:28:47.893: I/System.out(872): waiting for debugger to settle...
10-09 10:28:48.100: I/System.out(872): debugger has settled (1441)
10-09 10:28:48.273: I/dalvikvm(872): threadid=3: reacting to signal 3
10-09 10:28:48.402: I/dalvikvm(872): Wrote stack traces to '/data/anr/traces.txt'
10-09 10:28:48.773: I/dalvikvm(872): threadid=3: reacting to signal 3
10-09 10:28:48.813: I/dalvikvm(872): Wrote stack traces to '/data/anr/traces.txt'
10-09 10:28:49.213: D/gralloc_goldfish(872): Emulator without GPU emulation detected.
10-09 10:28:49.282: I/dalvikvm(872): threadid=3: reacting to signal 3
10-09 10:28:49.322: I/dalvikvm(872): Wrote stack traces to '/data/anr/traces.txt'
10-09 10:29:00.063: D/AndroidRuntime(872): Shutting down VM
10-09 10:29:00.063: W/dalvikvm(872): threadid=1: thread exiting with uncaught exception (group=0x409c01f8)
10-09 10:29:00.203: E/AndroidRuntime(872): FATAL EXCEPTION: main
10-09 10:29:00.203: E/AndroidRuntime(872): java.lang.NullPointerException
10-09 10:29:00.203: E/AndroidRuntime(872): at android.os.Parcel.readException(Parcel.java:1333)
10-09 10:29:00.203: E/AndroidRuntime(872): at android.os.Parcel.readException(Parcel.java:1281)
10-09 10:29:00.203: E/AndroidRuntime(872): at com.android.internal.telephony.ISms$Stub$Proxy.sendText(ISms.java:413)
10-09 10:29:00.203: E/AndroidRuntime(872): at android.telephony.SmsManager.sendTextMessage(SmsManager.java:87)
10-09 10:29:00.203: E/AndroidRuntime(872): at com.example.sms.SendSMSActivity.sendSMS(SendSMSActivity.java:134)
10-09 10:29:00.203: E/AndroidRuntime(872): at com.example.sms.SendSMSActivity.access$0(SendSMSActivity.java:74)
10-09 10:29:00.203: E/AndroidRuntime(872): at com.example.sms.SendSMSActivity$1.onClick(SendSMSActivity.java:59)
10-09 10:29:00.203: E/AndroidRuntime(872): at android.view.View.performClick(View.java:3511)
10-09 10:29:00.203: E/AndroidRuntime(872): at android.view.View$PerformClick.run(View.java:14105)
10-09 10:29:00.203: E/AndroidRuntime(872): at android.os.Handler.handleCallback(Handler.java:605)
10-09 10:29:00.203: E/AndroidRuntime(872): at android.os.Handler.dispatchMessage(Handler.java:92)
10-09 10:29:00.203: E/AndroidRuntime(872): at android.os.Looper.loop(Looper.java:137)
10-09 10:29:00.203: E/AndroidRuntime(872): at android.app.ActivityThread.main(ActivityThread.java:4424)
10-09 10:29:00.203: E/AndroidRuntime(872): at java.lang.reflect.Method.invokeNative(Native Method)
10-09 10:29:00.203: E/AndroidRuntime(872): at java.lang.reflect.Method.invoke(Method.java:511)
10-09 10:29:00.203: E/AndroidRuntime(872): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
10-09 10:29:00.203: E/AndroidRuntime(872): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
10-09 10:29:00.203: E/AndroidRuntime(872): at dalvik.system.NativeStart.main(Native Method)
10-09 10:29:00.803: I/dalvikvm(872): threadid=3: reacting to signal 3
10-09 10:29:00.823: I/dalvikvm(872): Wrote stack traces to '/data/anr/traces.txt'
10-09 10:29:48.632: I/dalvikvm(920): threadid=3: reacting to signal 3
10-09 10:29:48.793: I/dalvikvm(920): Wrote stack traces to '/data/anr/traces.txt'
10-09 10:29:49.133: I/dalvikvm(920): threadid=3: reacting to signal 3
10-09 10:29:49.173: I/dalvikvm(920): Wrote stack traces to '/data/anr/traces.txt'
10-09 10:29:49.203: D/gralloc_goldfish(920): Emulator without GPU emulation detected.
10-09 10:30:34.003: W/ActivityThread(960): Application com.example.sms is waiting for the debugger on port 8100...
10-09 10:30:34.093: I/System.out(960): Sending WAIT chunk
10-09 10:30:34.103: I/dalvikvm(960): Debugger is active
10-09 10:30:34.113: I/System.out(960): Debugger has connected
10-09 10:30:34.163: I/System.out(960): waiting for debugger to settle...
10-09 10:30:34.362: I/System.out(960): waiting for debugger to settle...
10-09 10:30:34.432: I/dalvikvm(960): threadid=3: reacting to signal 3
10-09 10:30:34.442: I/dalvikvm(960): Wrote stack traces to '/data/anr/traces.txt'
10-09 10:30:34.562: I/System.out(960): waiting for debugger to settle...
10-09 10:30:34.763: I/System.out(960): waiting for debugger to settle...
10-09 10:30:34.923: I/dalvikvm(960): threadid=3: reacting to signal 3
10-09 10:30:34.933: I/dalvikvm(960): Wrote stack traces to '/data/anr/traces.txt'
10-09 10:30:34.963: I/System.out(960): waiting for debugger to settle...
10-09 10:30:35.170: I/System.out(960): waiting for debugger to settle...
10-09 10:30:35.371: I/System.out(960): waiting for debugger to settle...
10-09 10:30:35.442: I/dalvikvm(960): threadid=3: reacting to signal 3
10-09 10:30:35.462: I/dalvikvm(960): Wrote stack traces to '/data/anr/traces.txt'
10-09 10:30:35.573: I/System.out(960): waiting for debugger to settle...
10-09 10:30:35.773: I/System.out(960): waiting for debugger to settle...
10-09 10:30:35.953: I/dalvikvm(960): threadid=3: reacting to signal 3
10-09 10:30:36.013: I/System.out(960): waiting for debugger to settle...
10-09 10:30:36.013: I/dalvikvm(960): Wrote stack traces to '/data/anr/traces.txt'
10-09 10:30:36.215: I/System.out(960): debugger has settled (1432)
10-09 10:30:36.452: I/dalvikvm(960): threadid=3: reacting to signal 3
10-09 10:30:36.582: I/dalvikvm(960): Wrote stack traces to '/data/anr/traces.txt'
10-09 10:30:36.953: I/dalvikvm(960): threadid=3: reacting to signal 3
10-09 10:30:36.983: I/dalvikvm(960): Wrote stack traces to '/data/anr/traces.txt'
10-09 10:30:37.462: I/dalvikvm(960): threadid=3: reacting to signal 3
10-09 10:30:37.472: I/dalvikvm(960): Wrote stack traces to '/data/anr/traces.txt'
10-09 10:30:37.502: D/gralloc_goldfish(960): Emulator without GPU emulation detected.
10-09 10:31:08.195: D/AndroidRuntime(960): Shutting down VM
10-09 10:31:08.195: W/dalvikvm(960): threadid=1: thread exiting with uncaught exception (group=0x409c01f8)
10-09 10:31:08.292: E/AndroidRuntime(960): FATAL EXCEPTION: main
10-09 10:31:08.292: E/AndroidRuntime(960): java.lang.NullPointerException
10-09 10:31:08.292: E/AndroidRuntime(960): at android.os.Parcel.readException(Parcel.java:1333)
10-09 10:31:08.292: E/AndroidRuntime(960): at android.os.Parcel.readException(Parcel.java:1281)
10-09 10:31:08.292: E/AndroidRuntime(960): at com.android.internal.telephony.ISms$Stub$Proxy.sendText(ISms.java:413)
10-09 10:31:08.292: E/AndroidRuntime(960): at android.telephony.SmsManager.sendTextMessage(SmsManager.java:87)
10-09 10:31:08.292: E/AndroidRuntime(960): at com.example.sms.SendSMSActivity.sendSMS(SendSMSActivity.java:134)
10-09 10:31:08.292: E/AndroidRuntime(960): at com.example.sms.SendSMSActivity.access$0(SendSMSActivity.java:74)
10-09 10:31:08.292: E/AndroidRuntime(960): at com.example.sms.SendSMSActivity$1.onClick(SendSMSActivity.java:57)
10-09 10:31:08.292: E/AndroidRuntime(960): at android.view.View.performClick(View.java:3511)
10-09 10:31:08.292: E/AndroidRuntime(960): at android.view.View$PerformClick.run(View.java:14105)
10-09 10:31:08.292: E/AndroidRuntime(960): at android.os.Handler.handleCallback(Handler.java:605)
10-09 10:31:08.292: E/AndroidRuntime(960): at android.os.Handler.dispatchMessage(Handler.java:92)
10-09 10:31:08.292: E/AndroidRuntime(960): at android.os.Looper.loop(Looper.java:137)
10-09 10:31:08.292: E/AndroidRuntime(960): at android.app.ActivityThread.main(ActivityThread.java:4424)
10-09 10:31:08.292: E/AndroidRuntime(960): at java.lang.reflect.Method.invokeNative(Native Method)
10-09 10:31:08.292: E/AndroidRuntime(960): at java.lang.reflect.Method.invoke(Method.java:511)
10-09 10:31:08.292: E/AndroidRuntime(960): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
10-09 10:31:08.292: E/AndroidRuntime(960): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
10-09 10:31:08.292: E/AndroidRuntime(960): at dalvik.system.NativeStart.main(Native Method)
10-09 10:31:08.913: I/dalvikvm(960): threadid=3: reacting to signal 3
10-09 10:31:08.923: I/dalvikvm(960): Wrote stack traces to '/data/anr/traces.txt'
10-09 10:31:11.983: I/Process(960): Sending signal. PID: 960 SIG: 9
10-09 10:31:28.392: I/dalvikvm(1008): threadid=3: reacting to signal 3
10-09 10:31:28.492: I/dalvikvm(1008): Wrote stack traces to '/data/anr/traces.txt'
10-09 10:31:28.843: D/gralloc_goldfish(1008): Emulator without GPU emulation detected.
10-09 10:31:32.713: D/AndroidRuntime(1008): Shutting down VM
10-09 10:31:32.713: W/dalvikvm(1008): threadid=1: thread exiting with uncaught exception (group=0x409c01f8)
10-09 10:31:32.803: E/AndroidRuntime(1008): FATAL EXCEPTION: main
10-09 10:31:32.803: E/AndroidRuntime(1008): java.lang.NullPointerException
10-09 10:31:32.803: E/AndroidRuntime(1008): at android.os.Parcel.readException(Parcel.java:1333)
10-09 10:31:32.803: E/AndroidRuntime(1008): at android.os.Parcel.readException(Parcel.java:1281)
10-09 10:31:32.803: E/AndroidRuntime(1008): at com.android.internal.telephony.ISms$Stub$Proxy.sendText(ISms.java:413)
10-09 10:31:32.803: E/AndroidRuntime(1008): at android.telephony.SmsManager.sendTextMessage(SmsManager.java:87)
10-09 10:31:32.803: E/AndroidRuntime(1008): at com.example.sms.SendSMSActivity.sendSMS(SendSMSActivity.java:134)
10-09 10:31:32.803: E/AndroidRuntime(1008): at com.example.sms.SendSMSActivity.access$0(SendSMSActivity.java:74)
10-09 10:31:32.803: E/AndroidRuntime(1008): at com.example.sms.SendSMSActivity$1.onClick(SendSMSActivity.java:57)
10-09 10:31:32.803: E/AndroidRuntime(1008): at android.view.View.performClick(View.java:3511)
10-09 10:31:32.803: E/AndroidRuntime(1008): at android.view.View$PerformClick.run(View.java:14105)
10-09 10:31:32.803: E/AndroidRuntime(1008): at android.os.Handler.handleCallback(Handler.java:605)
10-09 10:31:32.803: E/AndroidRuntime(1008): at android.os.Handler.dispatchMessage(Handler.java:92)
10-09 10:31:32.803: E/AndroidRuntime(1008): at android.os.Looper.loop(Looper.java:137)
10-09 10:31:32.803: E/AndroidRuntime(1008): at android.app.ActivityThread.main(ActivityThread.java:4424)
10-09 10:31:32.803: E/AndroidRuntime(1008): at java.lang.reflect.Method.invokeNative(Native Method)
10-09 10:31:32.803: E/AndroidRuntime(1008): at java.lang.reflect.Method.invoke(Method.java:511)
10-09 10:31:32.803: E/AndroidRuntime(1008): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
10-09 10:31:32.803: E/AndroidRuntime(1008): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
10-09 10:31:32.803: E/AndroidRuntime(1008): at dalvik.system.NativeStart.main(Native Method)
10-09 10:31:33.392: I/dalvikvm(1008): threadid=3: reacting to signal 3
10-09 10:31:33.402: I/dalvikvm(1008): Wrote stack traces to '/data/anr/traces.txt'
10-09 10:32:10.452: I/dalvikvm(1055): threadid=3: reacting to signal 3
10-09 10:32:10.523: I/dalvikvm(1055): Wrote stack traces to '/data/anr/traces.txt'
10-09 10:32:10.923: D/gralloc_goldfish(1055): Emulator without GPU emulation detected.
10-09 10:32:10.953: I/dalvikvm(1055): threadid=3: reacting to signal 3
10-09 10:32:10.973: I/dalvikvm(1055): Wrote stack traces to '/data/anr/traces.txt'
10-09 10:35:10.863: D/AndroidRuntime(1055): Shutting down VM
10-09 10:35:10.863: W/dalvikvm(1055): threadid=1: thread exiting with uncaught exception (group=0x409c01f8)
10-09 10:35:10.883: E/AndroidRuntime(1055): FATAL EXCEPTION: main
10-09 10:35:10.883: E/AndroidRuntime(1055): java.lang.NullPointerException
10-09 10:35:10.883: E/AndroidRuntime(1055): at android.os.Parcel.readException(Parcel.java:1333)
10-09 10:35:10.883: E/AndroidRuntime(1055): at android.os.Parcel.readException(Parcel.java:1281)
10-09 10:35:10.883: E/AndroidRuntime(1055): at com.android.internal.telephony.ISms$Stub$Proxy.sendText(ISms.java:413)
10-09 10:35:10.883: E/AndroidRuntime(1055): at android.telephony.SmsManager.sendTextMessage(SmsManager.java:87)
10-09 10:35:10.883: E/AndroidRuntime(1055): at com.example.sms.SendSMSActivity.sendSMS(SendSMSActivity.java:132)
10-09 10:35:10.883: E/AndroidRuntime(1055): at com.example.sms.SendSMSActivity.access$0(SendSMSActivity.java:72)
10-09 10:35:10.883: E/AndroidRuntime(1055): at com.example.sms.SendSMSActivity$1.onClick(SendSMSActivity.java:57)
10-09 10:35:10.883: E/AndroidRuntime(1055): at android.view.View.performClick(View.java:3511)
10-09 10:35:10.883: E/AndroidRuntime(1055): at android.view.View$PerformClick.run(View.java:14105)
10-09 10:35:10.883: E/AndroidRuntime(1055): at android.os.Handler.handleCallback(Handler.java:605)
10-09 10:35:10.883: E/AndroidRuntime(1055): at android.os.Handler.dispatchMessage(Handler.java:92)
10-09 10:35:10.883: E/AndroidRuntime(1055): at android.os.Looper.loop(Looper.java:137)
10-09 10:35:10.883: E/AndroidRuntime(1055): at android.app.ActivityThread.main(ActivityThread.java:4424)
10-09 10:35:10.883: E/AndroidRuntime(1055): at java.lang.reflect.Method.invokeNative(Native Method)
10-09 10:35:10.883: E/AndroidRuntime(1055): at java.lang.reflect.Method.invoke(Method.java:511)
10-09 10:35:10.883: E/AndroidRuntime(1055): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
10-09 10:35:10.883: E/AndroidRuntime(1055): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
10-09 10:35:10.883: E/AndroidRuntime(1055): at dalvik.system.NativeStart.main(Native Method)
10-09 10:35:11.453: I/dalvikvm(1055): threadid=3: reacting to signal 3
10-09 10:35:11.473: I/dalvikvm(1055): Wrote stack traces to '/data/anr/traces.txt'
10-09 10:35:50.673: I/dalvikvm(1104): threadid=3: reacting to signal 3
10-09 10:35:50.803: I/dalvikvm(1104): Wrote stack traces to '/data/anr/traces.txt'
10-09 10:35:51.112: D/gralloc_goldfish(1104): Emulator without GPU emulation detected.
10-09 10:35:51.142: I/dalvikvm(1104): threadid=3: reacting to signal 3
10-09 10:35:51.182: I/dalvikvm(1104): Wrote stack traces to '/data/anr/traces.txt'
10-09 10:37:12.383: D/AndroidRuntime(1104): Shutting down VM
10-09 10:37:12.383: W/dalvikvm(1104): threadid=1: thread exiting with uncaught exception (group=0x409c01f8)
10-09 10:37:12.403: E/AndroidRuntime(1104): FATAL EXCEPTION: main
10-09 10:37:12.403: E/AndroidRuntime(1104): java.lang.NullPointerException
10-09 10:37:12.403: E/AndroidRuntime(1104): at android.os.Parcel.readException(Parcel.java:1333)
10-09 10:37:12.403: E/AndroidRuntime(1104): at android.os.Parcel.readException(Parcel.java:1281)
10-09 10:37:12.403: E/AndroidRuntime(1104): at com.android.internal.telephony.ISms$Stub$Proxy.sendText(ISms.java:413)
10-09 10:37:12.403: E/AndroidRuntime(1104): at android.telephony.SmsManager.sendTextMessage(SmsManager.java:87)
10-09 10:37:12.403: E/AndroidRuntime(1104): at com.example.sms.SendSMSActivity.sendSMS(SendSMSActivity.java:132)
10-09 10:37:12.403: E/AndroidRuntime(1104): at com.example.sms.SendSMSActivity.access$0(SendSMSActivity.java:72)
10-09 10:37:12.403: E/AndroidRuntime(1104): at com.example.sms.SendSMSActivity$1.onClick(SendSMSActivity.java:57)
10-09 10:37:12.403: E/AndroidRuntime(1104): at android.view.View.performClick(View.java:3511)
10-09 10:37:12.403: E/AndroidRuntime(1104): at android.view.View$PerformClick.run(View.java:14105)
10-09 10:37:12.403: E/AndroidRuntime(1104): at android.os.Handler.handleCallback(Handler.java:605)
10-09 10:37:12.403: E/AndroidRuntime(1104): at android.os.Handler.dispatchMessage(Handler.java:92)
10-09 10:37:12.403: E/AndroidRuntime(1104): at android.os.Looper.loop(Looper.java:137)
10-09 10:37:12.403: E/AndroidRuntime(1104): at android.app.ActivityThread.main(ActivityThread.java:4424)
10-09 10:37:12.403: E/AndroidRuntime(1104): at java.lang.reflect.Method.invokeNative(Native Method)
10-09 10:37:12.403: E/AndroidRuntime(1104): at java.lang.reflect.Method.invoke(Method.java:511)
10-09 10:37:12.403: E/AndroidRuntime(1104): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
10-09 10:37:12.403: E/AndroidRuntime(1104): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
10-09 10:37:12.403: E/AndroidRuntime(1104): at dalvik.system.NativeStart.main(Native Method)
10-09 10:37:12.992: I/dalvikvm(1104): threadid=3: reacting to signal 3
10-09 10:37:13.012: I/dalvikvm(1104): Wrote stack traces to '/data/anr/traces.txt'
10-09 10:37:24.783: I/dalvikvm(1169): threadid=3: reacting to signal 3
10-09 10:37:24.882: I/dalvikvm(1169): Wrote stack traces to '/data/anr/traces.txt'
10-09 10:37:25.283: I/dalvikvm(1169): threadid=3: reacting to signal 3
10-09 10:37:25.303: I/dalvikvm(1169): Wrote stack traces to '/data/anr/traces.txt'
10-09 10:37:25.503: D/gralloc_goldfish(1169): Emulator without GPU emulation detected.
10-09 10:37:34.952: W/IInputConnectionWrapper(1169): showStatusIcon on inactive InputConnection
10-09 10:37:45.533: D/AndroidRuntime(1169): Shutting down VM
10-09 10:37:45.533: W/dalvikvm(1169): threadid=1: thread exiting with uncaught exception (group=0x409c01f8)
10-09 10:37:45.563: E/AndroidRuntime(1169): FATAL EXCEPTION: main
10-09 10:37:45.563: E/AndroidRuntime(1169): java.lang.NullPointerException
10-09 10:37:45.563: E/AndroidRuntime(1169): at android.os.Parcel.readException(Parcel.java:1333)
10-09 10:37:45.563: E/AndroidRuntime(1169): at android.os.Parcel.readException(Parcel.java:1281)
10-09 10:37:45.563: E/AndroidRuntime(1169): at com.android.internal.telephony.ISms$Stub$Proxy.sendText(ISms.java:413)
10-09 10:37:45.563: E/AndroidRuntime(1169): at android.telephony.SmsManager.sendTextMessage(SmsManager.java:87)
10-09 10:37:45.563: E/AndroidRuntime(1169): at com.example.sms.SendSMSActivity.sendSMS(SendSMSActivity.java:132)
10-09 10:37:45.563: E/AndroidRuntime(1169): at com.example.sms.SendSMSActivity.access$0(SendSMSActivity.java:72)
10-09 10:37:45.563: E/AndroidRuntime(1169): at com.example.sms.SendSMSActivity$1.onClick(SendSMSActivity.java:57)
10-09 10:37:45.563: E/AndroidRuntime(1169): at android.view.View.performClick(View.java:3511)
10-09 10:37:45.563: E/AndroidRuntime(1169): at android.view.View$PerformClick.run(View.java:14105)
10-09 10:37:45.563: E/AndroidRuntime(1169): at android.os.Handler.handleCallback(Handler.java:605)
10-09 10:37:45.563: E/AndroidRuntime(1169): at android.os.Handler.dispatchMessage(Handler.java:92)
10-09 10:37:45.563: E/AndroidRuntime(1169): at android.os.Looper.loop(Looper.java:137)
10-09 10:37:45.563: E/AndroidRuntime(1169): at android.app.ActivityThread.main(ActivityThread.java:4424)
10-09 10:37:45.563: E/AndroidRuntime(1169): at java.lang.reflect.Method.invokeNative(Native Method)
10-09 10:37:45.563: E/AndroidRuntime(1169): at java.lang.reflect.Method.invoke(Method.java:511)
10-09 10:37:45.563: E/AndroidRuntime(1169): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
10-09 10:37:45.563: E/AndroidRuntime(1169): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
10-09 10:37:45.563: E/AndroidRuntime(1169): at dalvik.system.NativeStart.main(Native Method)
10-09 10:37:46.122: I/dalvikvm(1169): threadid=3: reacting to signal 3
10-09 10:37:46.142: I/dalvikvm(1169): Wrote stack traces to '/data/anr/traces.txt'
smsactivity
public class SendSMSActivity extends Activity {
Button btnSendSMS;
EditText txtPhoneNo;
EditText txtMessage;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btnSendSMS = (Button) findViewById(R.id.btnSendSMS);
txtPhoneNo = (EditText) findViewById(R.id.txtPhoneNo);
txtMessage = (EditText) findViewById(R.id.txtMessage);
btnSendSMS.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
String phoneNo = txtPhoneNo.getText().toString();
String message = txtMessage.getText().toString();
if (phoneNo.length() > 0 && message.length() > 0)
{
TelephonyManager telMgr = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
int simState = telMgr.getSimState();
switch (simState) {
case TelephonyManager.SIM_STATE_ABSENT:
Toast.makeText(getBaseContext(), "No Sim Card found",
Toast.LENGTH_SHORT).show();
break;
case TelephonyManager.SIM_STATE_NETWORK_LOCKED:
// do something
break;
case TelephonyManager.SIM_STATE_PIN_REQUIRED:
// do something
break;
case TelephonyManager.SIM_STATE_PUK_REQUIRED:
// do something
break;
case TelephonyManager.SIM_STATE_READY:
sendSMS(phoneNo, message); // method to send message
break;
case TelephonyManager.SIM_STATE_UNKNOWN:
// do something
break;
}
} else
Toast.makeText(getBaseContext(),
"Please enter both phone number and message.",
Toast.LENGTH_SHORT).show();
}
private void sendSMS(String phoneNumber, String message) {
String SENT = "SMS_SENT";
String DELIVERED = "SMS_DELIVERED";
PendingIntent sentPI = PendingIntent.getBroadcast(
SendSMSActivity.this, 0, new Intent(SENT), 0);
PendingIntent deliveredPI = PendingIntent.getBroadcast(
SendSMSActivity.this, 0, new Intent(DELIVERED), 0);
// ---when the SMS has been sent---final String string =
// "deprecation";
registerReceiver(new BroadcastReceiver() {
#Override
public void onReceive(Context arg0, Intent arg1) {
switch (getResultCode()) {
case Activity.RESULT_OK:
Toast.makeText(SendSMSActivity.this, "SMS sent",
Toast.LENGTH_SHORT).show();
break;
case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
Toast.makeText(SendSMSActivity.this,
"Generic failure", Toast.LENGTH_SHORT)
.show();
break;
case SmsManager.RESULT_ERROR_NO_SERVICE:
Toast.makeText(SendSMSActivity.this, "No service",
Toast.LENGTH_SHORT).show();
break;
case SmsManager.RESULT_ERROR_NULL_PDU:
Toast.makeText(SendSMSActivity.this, "Null PDU",
Toast.LENGTH_SHORT).show();
break;
case SmsManager.RESULT_ERROR_RADIO_OFF:
Toast.makeText(getBaseContext(), "Radio off",
Toast.LENGTH_SHORT).show();
break;
}
}
}, new IntentFilter(SENT));
// ---when the SMS has been delivered---
registerReceiver(new BroadcastReceiver() {
#Override
public void onReceive(Context arg0, Intent arg1) {
switch (getResultCode()) {
case Activity.RESULT_OK:
Toast.makeText(SendSMSActivity.this,
"SMS delivered", Toast.LENGTH_SHORT).show();
break;
case Activity.RESULT_CANCELED:
Toast.makeText(SendSMSActivity.this,
"SMS not delivered", Toast.LENGTH_SHORT)
.show();
break;
}
}
}, new IntentFilter(DELIVERED));
SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage(phoneNumber, null, message, sentPI,
deliveredPI);
}
});
}
}

How to communicate with a USB device?

I am trying to establish USB communication as host. I am following the examples here http://developer.android.com/guide/topics/usb/host.html but I cannot get this working. Here is my code:
private static final String ACTION_USB_PERMISSION = "com.multitools.andres.LCView";
UsbDevice device;
//Pide permisos al usuario para comunicacion con el dispositivo USB
private final BroadcastReceiver mUsbReceiver = new BroadcastReceiver() {
#Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (ACTION_USB_PERMISSION.equals(action)) {
synchronized (this) {
UsbDevice device = (UsbDevice)intent.getParcelableExtra(UsbManager.EXTRA_DEVICE);
if (intent.getBooleanExtra(UsbManager.EXTRA_PERMISSION_GRANTED, false)) {
if(device != null){
//call method to set up device communication
}
}
else {
Log.d(TAG, "permission denied for device " + device);
}
}
}
}
};
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if(DEBUG) Log.i(TAG, "onCreate() -> MainMenu");
actionBar = getActionBar(); //obtengo el ActionBar
actionBar.setDisplayHomeAsUpEnabled(true); //el icono de la aplicacion funciona como boton HOME
//Menu
setListAdapter(new ArrayAdapter<String>(MainMenu.this, android.R.layout.simple_list_item_1, MenuNames));
//USB
if(DEBUG) Log.i(TAG, "Setting UsbManager -> MainMenu");
UsbManager mUsbManager = (UsbManager) getSystemService(Context.USB_SERVICE);
PendingIntent mPermissionIntent;
if(DEBUG) Log.i(TAG, "Setting PermissionIntent -> MainMenu");
mPermissionIntent = PendingIntent.getBroadcast(this, 0, new Intent(ACTION_USB_PERMISSION), 0);
if(DEBUG) Log.i(TAG, "Setting IntentFilter -> MainMenu");
IntentFilter filter = new IntentFilter(ACTION_USB_PERMISSION);
if(DEBUG) Log.i(TAG, "Setting registerReceiver -> MainMenu");
registerReceiver(mUsbReceiver, filter);
if(DEBUG) Log.i(TAG, "Setting requestPermission -> MainMenu");
mUsbManager.requestPermission(device, mPermissionIntent);
}
I get the Force Close dialog when I uncomment the line mUsbManager.requestPermission(device, mPermissionIntent); If I comment it, I don't get the force close but it doesnt work. I think the problem is in:
private static final String ACTION_USB_PERMISSION = "com.multitools.andres.LCView";
On Google's example it is as:
private static final String ACTION_USB_PERMISSION = "com.android.example.USB_PERMISSION";
But I dont know what exactly I have to put there and i could not find any explanation about that. What i have to put there or where is my error ? Here is the LogCat i am getting when i start my application:
04-17 00:57:50.944: I/dalvikvm(1362): threadid=3: reacting to signal 3
04-17 00:57:51.331: I/dalvikvm(1362): Wrote stack traces to '/data/anr/traces.txt'
04-17 00:57:51.981: I/(1362): onCreate() -> MainMenu
04-17 00:57:52.013: I/dalvikvm(1362): threadid=3: reacting to signal 3
04-17 00:57:52.151: I/dalvikvm(1362): Wrote stack traces to '/data/anr/traces.txt'
04-17 00:57:52.570: I/dalvikvm(1362): threadid=3: reacting to signal 3
04-17 00:57:52.731: I/dalvikvm(1362): Wrote stack traces to '/data/anr/traces.txt'
04-17 00:57:53.122: I/dalvikvm(1362): threadid=3: reacting to signal 3
04-17 00:57:53.231: I/dalvikvm(1362): Wrote stack traces to '/data/anr/traces.txt'
04-17 00:57:53.390: I/(1362): Setting UsbManager -> MainMenu
04-17 00:57:53.451: I/(1362): Setting PermissionIntent -> MainMenu
04-17 00:57:53.470: I/(1362): Setting IntentFilter -> MainMenu
04-17 00:57:53.470: I/(1362): Setting registerReceiver -> MainMenu
04-17 00:57:53.511: I/(1362): Setting requestPermission -> MainMenu
04-17 00:57:53.660: I/dalvikvm(1362): threadid=3: reacting to signal 3
04-17 00:57:53.791: I/dalvikvm(1362): Wrote stack traces to '/data/anr/traces.txt'
04-17 00:57:54.311: I/dalvikvm(1362): threadid=3: reacting to signal 3
04-17 00:57:54.401: I/dalvikvm(1362): Wrote stack traces to '/data/anr/traces.txt'
04-17 00:57:54.531: I/(1362): onCreateOptionsMenu() -> MainMenu
04-17 00:57:54.683: I/dalvikvm(1362): threadid=3: reacting to signal 3
04-17 00:57:54.772: I/dalvikvm(1362): Wrote stack traces to '/data/anr/traces.txt'
04-17 00:57:55.186: I/dalvikvm(1362): threadid=3: reacting to signal 3
04-17 00:57:55.291: I/dalvikvm(1362): Wrote stack traces to '/data/anr/traces.txt'
04-17 00:57:55.661: I/dalvikvm(1362): threadid=3: reacting to signal 3
04-17 00:57:55.751: I/dalvikvm(1362): Wrote stack traces to '/data/anr/traces.txt'
04-17 00:57:55.791: D/gralloc_goldfish(1362): Emulator without GPU emulation detected.
04-17 01:11:47.323: I/dalvikvm(1459): threadid=3: reacting to signal 3
04-17 01:11:47.720: I/dalvikvm(1459): Wrote stack traces to '/data/anr/traces.txt'
04-17 01:11:48.124: I/dalvikvm(1459): threadid=3: reacting to signal 3
04-17 01:11:48.291: I/dalvikvm(1459): Wrote stack traces to '/data/anr/traces.txt'
04-17 01:11:48.452: I/(1459): onCreate() -> MainMenu
04-17 01:11:48.691: I/dalvikvm(1459): threadid=3: reacting to signal 3
04-17 01:11:48.813: I/dalvikvm(1459): Wrote stack traces to '/data/anr/traces.txt'
04-17 01:11:49.172: I/dalvikvm(1459): threadid=3: reacting to signal 3
04-17 01:11:49.321: I/dalvikvm(1459): Wrote stack traces to '/data/anr/traces.txt'
04-17 01:11:49.653: I/dalvikvm(1459): threadid=3: reacting to signal 3
04-17 01:11:49.821: I/dalvikvm(1459): Wrote stack traces to '/data/anr/traces.txt'
04-17 01:11:49.901: I/(1459): Setting UsbManager -> MainMenu
04-17 01:11:49.931: I/(1459): Setting PermissionIntent -> MainMenu
04-17 01:11:50.021: I/(1459): Setting IntentFilter -> MainMenu
04-17 01:11:50.031: I/(1459): Setting registerReceiver -> MainMenu
04-17 01:11:50.051: I/(1459): Setting requestPermission -> MainMenu
04-17 01:11:50.071: D/AndroidRuntime(1459): Shutting down VM
04-17 01:11:50.133: W/dalvikvm(1459): threadid=1: thread exiting with uncaught exception (group=0x409c01f8)
04-17 01:11:50.231: I/dalvikvm(1459): threadid=3: reacting to signal 3
04-17 01:11:50.331: I/dalvikvm(1459): Wrote stack traces to '/data/anr/traces.txt'
04-17 01:11:50.401: E/AndroidRuntime(1459): FATAL EXCEPTION: main
04-17 01:11:50.401: E/AndroidRuntime(1459): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.multitools.andres/com.multitools.andres.MainMenu}: java.lang.NullPointerException
04-17 01:11:50.401: E/AndroidRuntime(1459): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
04-17 01:11:50.401: E/AndroidRuntime(1459): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
04-17 01:11:50.401: E/AndroidRuntime(1459): at android.app.ActivityThread.access$600(ActivityThread.java:123)
04-17 01:11:50.401: E/AndroidRuntime(1459): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
04-17 01:11:50.401: E/AndroidRuntime(1459): at android.os.Handler.dispatchMessage(Handler.java:99)
04-17 01:11:50.401: E/AndroidRuntime(1459): at android.os.Looper.loop(Looper.java:137)
04-17 01:11:50.401: E/AndroidRuntime(1459): at android.app.ActivityThread.main(ActivityThread.java:4424)
04-17 01:11:50.401: E/AndroidRuntime(1459): at java.lang.reflect.Method.invokeNative(Native Method)
04-17 01:11:50.401: E/AndroidRuntime(1459): at java.lang.reflect.Method.invoke(Method.java:511)
04-17 01:11:50.401: E/AndroidRuntime(1459): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
04-17 01:11:50.401: E/AndroidRuntime(1459): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
04-17 01:11:50.401: E/AndroidRuntime(1459): at dalvik.system.NativeStart.main(Native Method)
04-17 01:11:50.401: E/AndroidRuntime(1459): Caused by: java.lang.NullPointerException
04-17 01:11:50.401: E/AndroidRuntime(1459): at android.os.Parcel.readException(Parcel.java:1333)
04-17 01:11:50.401: E/AndroidRuntime(1459): at android.os.Parcel.readException(Parcel.java:1281)
04-17 01:11:50.401: E/AndroidRuntime(1459): at android.hardware.usb.IUsbManager$Stub$Proxy.requestDevicePermission(IUsbManager.java:535)
04-17 01:11:50.401: E/AndroidRuntime(1459): at android.hardware.usb.UsbManager.requestPermission(UsbManager.java:361)
04-17 01:11:50.401: E/AndroidRuntime(1459): at com.multitools.andres.MainMenu.onCreate(MainMenu.java:80)
04-17 01:11:50.401: E/AndroidRuntime(1459): at android.app.Activity.performCreate(Activity.java:4465)
04-17 01:11:50.401: E/AndroidRuntime(1459): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
04-17 01:11:50.401: E/AndroidRuntime(1459): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
04-17 01:11:50.401: E/AndroidRuntime(1459): ... 11 more
04-17 01:11:50.751: I/dalvikvm(1459): threadid=3: reacting to signal 3
04-17 01:11:50.851: I/dalvikvm(1459): Wrote stack traces to '/data/anr/traces.txt'
04-17 01:11:51.331: I/dalvikvm(1459): threadid=3: reacting to signal 3
04-17 01:11:51.403: I/dalvikvm(1459): Wrote stack traces to '/data/anr/traces.txt'
04-17 01:11:51.774: I/dalvikvm(1459): threadid=3: reacting to signal 3
04-17 01:11:51.961: I/dalvikvm(1459): Wrote stack traces to '/data/anr/traces.txt'
Thanks you :)
That string is just a marker so you recognize the intent that is returned when you call registerReceiver(mUsbReceiver, filter);. That isn't the problem.
I think the problem is here:
UsbManager mUsbManager = (UsbManager) getSystemService(Context.USB_SERVICE);
This line is supposed to get you your USB Manager, but as far as I recall not all phones have to support the Android USB Accessory API. This line is probably just assigning null to mUsbManager which then causes you NullPointerException when you call a method on it further down in the code. Trying checking if that isn't null before making a call on it.
For more info, checkout these links:
http://developer.android.com/guide/topics/usb/index.html
http://developer.android.com/guide/topics/usb/accessory.html
EDIT:
I think I see what the issue is now. You're right, it's not the USB Manager. It's the UsbDevice object (device). It is never initialized anywhere in your code. In this line :
mUsbManager.requestPermission(device, mPermissionIntent);
you're basically firing off an intent to ask the user if it's okay for you to work with the device represented by the UsbDevice object device. However when this call gets fired device has not yet been initialized (and therefore has the default value of null). So when you try to request permission you end up getting a NullPointerException instead of the expected result. To fix this you need to figure out which device you want to connect to and assign it to device. Look in here, under "Enumerating devices" to figure out different ways to do that. One way, if you know the name of the device you want to connect to, is to make the following calls after you retrieve the Usb Manager:
HashMap<String, UsbDevice> deviceList = mUsbManager.getDeviceList();
device = deviceList.get("<deviceName>");
(Obviously, you would replace <deviceName> with the actual name of the device.
minSdkVersion must >= 12
To enable USB host API support you should add a file named
android.hardware.usb.host.xml and containing the following lines:
<permissions>
<feature name="android.hardware.usb.host"/>

Google API MapView OutOfMemory after setting the MapView to specific width and height

i searched for this Problem, and i found some stackoverflow Questions about the same but without any idea how to resolve the problem.
I created an activity and i want to add a really small mapview (like 140w X 70h). It is only to show a small preview of where the place is. When you click this little mapview you get a new inflate to a new activity with the hole map.
MapView:
<com.google.android.maps.MapView android:id="#+id/mapview"
android:layout_width="140dip"
android:layout_height="80dip"
android:layout_below="#id/attributes"
android:layout_alignParentRight="true"
android:apiKey="****"
android:paddingBottom="60dp"/>
LogCat:
05-30 14:34:53.758: ERROR/dalvikvm(1608): Out of memory: Heap Size=4039KB, Allocated=2768KB, Bitmap Size=625KB
05-30 14:34:53.758: DEBUG/AndroidRuntime(1608): Shutting down VM
05-30 14:34:53.758: WARN/dalvikvm(1608): threadid=1: thread exiting with uncaught exception (group=0x400259f8)
05-30 14:34:53.768: ERROR/AndroidRuntime(1608): FATAL EXCEPTION: main
05-30 14:34:53.768: ERROR/AndroidRuntime(1608): java.lang.OutOfMemoryError
05-30 14:34:53.768: ERROR/AndroidRuntime(1608): at com.google.googlenav.map.Map.resize(Unknown Source)
05-30 14:34:53.768: ERROR/AndroidRuntime(1608): at com.google.android.maps.MapView.onMeasure(MapView.java:554)
05-30 14:34:53.768: ERROR/AndroidRuntime(1608): at android.view.View.measure(View.java:8172)
05-30 14:34:53.768: ERROR/AndroidRuntime(1608): at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:578)
05-30 14:34:53.768: ERROR/AndroidRuntime(1608): at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:362)
05-30 14:34:53.768: ERROR/AndroidRuntime(1608): at android.view.View.measure(View.java:8172)
05-30 14:34:53.768: ERROR/AndroidRuntime(1608): at android.widget.ScrollView.measureChildWithMargins(ScrollView.java:989)
05-30 14:34:53.768: ERROR/AndroidRuntime(1608): at android.widget.FrameLayout.onMeasure(FrameLayout.java:245)
05-30 14:34:53.768: ERROR/AndroidRuntime(1608): at android.widget.ScrollView.onMeasure(ScrollView.java:286)
05-30 14:34:53.768: ERROR/AndroidRuntime(1608): at android.view.View.measure(View.java:8172)
05-30 14:34:53.768: ERROR/AndroidRuntime(1608): at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:578)
05-30 14:34:53.768: ERROR/AndroidRuntime(1608): at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:362)
05-30 14:34:53.768: ERROR/AndroidRuntime(1608): at android.view.View.measure(View.java:8172)
05-30 14:34:53.768: ERROR/AndroidRuntime(1608): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3140)
05-30 14:34:53.768: ERROR/AndroidRuntime(1608): at android.widget.FrameLayout.onMeasure(FrameLayout.java:245)
05-30 14:34:53.768: ERROR/AndroidRuntime(1608): at android.view.View.measure(View.java:8172)
05-30 14:34:53.768: ERROR/AndroidRuntime(1608): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3140)
05-30 14:34:53.768: ERROR/AndroidRuntime(1608): at android.widget.FrameLayout.onMeasure(FrameLayout.java:245)
05-30 14:34:53.768: ERROR/AndroidRuntime(1608): at android.view.View.measure(View.java:8172)
05-30 14:34:53.768: ERROR/AndroidRuntime(1608): at android.view.ViewRoot.performTraversals(ViewRoot.java:805)
05-30 14:34:53.768: ERROR/AndroidRuntime(1608): at android.view.ViewRoot.handleMessage(ViewRoot.java:1744)
05-30 14:34:53.768: ERROR/AndroidRuntime(1608): at android.os.Handler.dispatchMessage(Handler.java:99)
05-30 14:34:53.768: ERROR/AndroidRuntime(1608): at android.os.Looper.loop(Looper.java:144)
05-30 14:34:53.768: ERROR/AndroidRuntime(1608): at android.app.ActivityThread.main(ActivityThread.java:4937)
05-30 14:34:53.768: ERROR/AndroidRuntime(1608): at java.lang.reflect.Method.invokeNative(Native Method)
05-30 14:34:53.768: ERROR/AndroidRuntime(1608): at java.lang.reflect.Method.invoke(Method.java:521)
05-30 14:34:53.768: ERROR/AndroidRuntime(1608): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
05-30 14:34:53.768: ERROR/AndroidRuntime(1608): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
05-30 14:34:53.768: ERROR/AndroidRuntime(1608): at dalvik.system.NativeStart.main(Native Method)
this is the error. When i use fill_parent it works, but i dont want a mapview with fill_parent.
Maybe you guys know another way to get a preview small image of the current (or given) position on the map as image.
Isn't it possible to show a small mapview ?
thanks
If you just want to show a static map without interaction I recommend the static map api from google. You can define markers, the center, the size and some labels and it returns a generated image that can be easily shown inside a ImageView. The benefit of this: You don't have to invoke a complete MapView for just a small map image. No overhead of memory or user interaction. Perfect for the scenario you have.

Categories

Resources