アクティビティ A から と であるサービス B にデータを渡したいと思いuserName
ますphoneNumber
。サービス B のみphoneNumber
(ここでは電話番号が重要です) が使用され、 arandomNumber
が生成されます。サービス B からアクティビティ C に渡されるデータはuserName
、phoneNumber
およびrandomNumber
です。
以下に示すこのコードを使用しようとしていますが、機能しません。
アクティビティ A:
Intent goToServiceB = new Intent(getApplicationContext(),ServiceB.class);
goToServiceB.putExtra("passedPhoneNumberAtoS", phoneNumberStr);
goToServiceB.putExtra("passedUserNameAtoS", userNameStr);
startService(goToServiceB);
サービス B:
public int onStartCommand(Intent intent, int flags, int startId) {
// TODO Auto-generated method stub
String phoneNumber = intent.getStringExtra("passedPhoneNumberAtoS");
String userName = intent.getStringExtra("passedUserNameAtoS");
return Service.START_NOT_STICKY;
}
サービス B 自体には、別のインテントがあります。
Intent goToActivityC = new Intent(getApplicationContext(),ActivityC.class);
goToActivityC.putExtra("passedPhoneNumberStoA", phoneNumberStr);
goToActivityC.putExtra("passedUserNameStoA", userNameStr);
goToActivityC.putExtra("passedRandomNumberStoA", RandomNumberStr);
startactivity(goToActivityC);
アクティビティ C:
Intent intent=new Intent();
String phoneNumber = intent.getStringExtra("passedPhoneNumberStoA");
String userName = intent.getStringExtra("passedUserNameStoA");
String RandomNumber=intent.getStringExtra("passedRandomNumberStoA");
私のlogcat:
08-03 14:19:42.882: E/Trace(1923): error opening trace file: No such file or directory (2)
08-03 14:19:44.983: D/gralloc_goldfish(1923): Emulator without GPU emulation detected.
08-03 14:19:45.153: W/IInputConnectionWrapper(1923): showStatusIcon on inactive InputConnection
08-03 14:19:47.792: D/dalvikvm(1923): GC_CONCURRENT freed 84K, 7% free 2765K/2972K, paused 79ms+46ms, total 236ms
08-03 14:20:03.792: D/dalvikvm(1923): GC_FOR_ALLOC freed 54K, 6% free 2931K/3104K, paused 36ms, total 57ms
08-03 14:20:03.812: I/dalvikvm-heap(1923): Grow heap (frag case) to 4.050MB for 1127536-byte allocation
08-03 14:20:03.964: D/dalvikvm(1923): GC_FOR_ALLOC freed 50K, 6% free 3982K/4208K, paused 152ms, total 152ms
08-03 14:20:04.113: D/dalvikvm(1923): GC_CONCURRENT freed 1K, 6% free 3987K/4208K, paused 4ms+97ms, total 154ms
08-03 14:20:04.202: D/AndroidRuntime(1923): Shutting down VM
08-03 14:20:04.202: W/dalvikvm(1923): threadid=1: thread exiting with uncaught exception (group=0x40a71930)
08-03 14:20:04.232: E/AndroidRuntime(1923): FATAL EXCEPTION: main
08-03 14:20:04.232: E/AndroidRuntime(1923): java.lang.IllegalStateException: Could not execute method of the activity
08-03 14:20:04.232: E/AndroidRuntime(1923): at android.view.View$1.onClick(View.java:3599)
08-03 14:20:04.232: E/AndroidRuntime(1923): at android.view.View.performClick(View.java:4204)
08-03 14:20:04.232: E/AndroidRuntime(1923): at android.view.View$PerformClick.run(View.java:17355)
08-03 14:20:04.232: E/AndroidRuntime(1923): at android.os.Handler.handleCallback(Handler.java:725)
08-03 14:20:04.232: E/AndroidRuntime(1923): at android.os.Handler.dispatchMessage(Handler.java:92)
08-03 14:20:04.232: E/AndroidRuntime(1923): at android.os.Looper.loop(Looper.java:137)
08-03 14:20:04.232: E/AndroidRuntime(1923): at android.app.ActivityThread.main(ActivityThread.java:5041)
08-03 14:20:04.232: E/AndroidRuntime(1923): at java.lang.reflect.Method.invokeNative(Native Method)
08-03 14:20:04.232: E/AndroidRuntime(1923): at java.lang.reflect.Method.invoke(Method.java:511)
08-03 14:20:04.232: E/AndroidRuntime(1923): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
08-03 14:20:04.232: E/AndroidRuntime(1923): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
08-03 14:20:04.232: E/AndroidRuntime(1923): at dalvik.system.NativeStart.main(Native Method)
08-03 14:20:04.232: E/AndroidRuntime(1923): Caused by: java.lang.reflect.InvocationTargetException
08-03 14:20:04.232: E/AndroidRuntime(1923): at java.lang.reflect.Method.invokeNative(Native Method)
08-03 14:20:04.232: E/AndroidRuntime(1923): at java.lang.reflect.Method.invoke(Method.java:511)
08-03 14:20:04.232: E/AndroidRuntime(1923): at android.view.View$1.onClick(View.java:3594)
08-03 14:20:04.232: E/AndroidRuntime(1923): ... 11 more
08-03 14:20:04.232: E/AndroidRuntime(1923): Caused by: android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application
08-03 14:20:04.232: E/AndroidRuntime(1923): at android.view.ViewRootImpl.setView(ViewRootImpl.java:571)
08-03 14:20:04.232: E/AndroidRuntime(1923): at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:246)
08-03 14:20:04.232: E/AndroidRuntime(1923): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:69)
08-03 14:20:04.232: E/AndroidRuntime(1923): at android.app.Dialog.show(Dialog.java:281)
08-03 14:20:04.232: E/AndroidRuntime(1923): at com.beproject.groupmessenger.UserRegistration.showAlert(UserRegistration.java:91)
08-03 14:20:04.232: E/AndroidRuntime(1923): at com.beproject.groupmessenger.UserRegistration.submit(UserRegistration.java:97)
08-03 14:20:04.232: E/AndroidRuntime(1923): ... 14 more
上記の問題の簡単な解決策を教えてください。私はたくさん検索しましたが、理解できる解決策を得ることができません。