我正在开发一个 Android 项目,我必须将数据从一个活动发送到另一个活动。但是,当我将数据从一个活动发送到另一个活动时,它不会将数据从一个活动发送到另一个活动。
从其他人接收数据的部分代码是:
Intent intent=getIntent();
String str,str1;
str=intent.getExtras().getString("phoneno");
Log.d("completre", "complete");
phonePhoneno.setText(str);
Log.d("complete","complete1");
if(intent.getExtras()==null) {
txtMessage.setText("u duffer write program properly");
} else {
str1=intent.getExtras().toString();
txtMessage.setText(str1);
Log.d("complete","complete2");
}
我用于从其他活动发送数据的部分代码是:
if(v.getId()==R.id.main_act) {
String str=txtText.getText().toString();
Intent intent=new Intent(getApplicationContext(), MainActivity.class);
intent.putExtra("username",str);
intent.putExtra("phoneno", phoneno);
startActivity(intent);
}
当我尝试通过单击按钮接收数据时,它会强制关闭。
在这个项目中,我在第一个活动中进行了两项活动,我正在阅读电话号码。将其发送到第二个活动只是为了将其保存以备将来使用。在第二个活动中,我有一个编辑文本,其中我通过语音识别系统添加文本,之后我通过上面显示的单击按钮将数据电话号码和编辑文本字段从第二个活动发送到第一个活动(在代码的第二部分) . 它正在发送电话号码但不编辑文本内容(猜测),当我单击完成按钮(在第一个活动中填写两个字段)时,它会在电话号码字段中添加电话号码但不添加消息。
应用程序未自行关闭时的最新日志猫
04-13 13:33:46.206: I/TextToSpeech(834): Sucessfully bound to com.svox.pico
04-13 13:33:46.206: W/TextToSpeech(834): speak failed: not bound to TTS engine
04-13 13:33:47.005: I/TextToSpeech(834): Connected to ComponentInfo{com.svox.pico/com.svox.pico.PicoService}
04-13 13:33:47.125: E/test(834): hhhhhhhhhhhhhhhhh
04-13 13:33:47.125: I/Choreographer(834): Skipped 174 frames! The application may be doing too much work on its main thread.
04-13 13:33:47.575: I/Choreographer(834): Skipped 69 frames! The application may be doing too much work on its main thread.
04-13 13:33:56.535: W/IInputConnectionWrapper(834): showStatusIcon on inactive InputConnection
04-13 13:33:56.535: I/Choreographer(834): Skipped 174 frames! The application may be doing too much work on its main thread.
04-13 13:33:56.975: D/dalvikvm(834): GC_CONCURRENT freed 127K, 9% free 3017K/3288K, paused 37ms+5ms, total 108ms
04-13 13:34:00.274: V/(834): Got a contact result: content://com.android.contacts/data/3
04-13 13:34:00.674: V/(834): Got phone no : (986) 743-561
04-13 13:34:00.914: I/Choreographer(834): Skipped 164 frames! The application may be doing too much work on its main thread.
04-13 13:34:01.244: I/Choreographer(834): Skipped 37 frames! The application may be doing too much work on its main thread.
04-13 13:34:05.494: I/Choreographer(834): Skipped 139 frames! The application may be doing too much work on its main thread.
04-13 13:34:05.974: I/Choreographer(834): Skipped 60 frames! The application may be doing too much work on its main thread.
04-13 13:34:12.965: I/TextToSpeech(834): Sucessfully bound to com.svox.pico
04-13 13:34:12.965: W/TextToSpeech(834): speak failed: not bound to TTS engine
04-13 13:34:13.065: I/TextToSpeech(834): Connected to ComponentInfo{com.svox.pico/com.svox.pico.PicoService}
04-13 13:34:13.155: E/test(834): hhhhhhhhhhhhhhhhh
04-13 13:34:13.155: I/Choreographer(834): Skipped 35 frames! The application may be doing too much work on its main thread.
04-13 13:34:14.425: I/Choreographer(834): Skipped 308 frames! The application may be doing too much work on its main thread.
04-13 13:34:15.235: I/Choreographer(834): Skipped 95 frames! The application may be doing too much work on its main thread.
04-13 13:34:16.265: I/Choreographer(834): Skipped 31 frames! The application may be doing too much work on its main thread.
04-13 13:34:20.025: D/completre(834): complete
04-13 13:34:20.035: D/AndroidRuntime(834): Shutting down VM
04-13 13:34:20.035: W/dalvikvm(834): threadid=1: thread exiting with uncaught exception (group=0x40a71930)
04-13 13:34:20.085: E/AndroidRuntime(834): FATAL EXCEPTION: main
04-13 13:34:20.085: E/AndroidRuntime(834): java.lang.NullPointerException
04-13 13:34:20.085: E/AndroidRuntime(834): at com.example.sms.MainActivity.onClick(MainActivity.java:322)
04-13 13:34:20.085: E/AndroidRuntime(834): at android.view.View.performClick(View.java:4204)
04-13 13:34:20.085: E/AndroidRuntime(834): at android.view.View$PerformClick.run(View.java:17355)
04-13 13:34:20.085: E/AndroidRuntime(834): at android.os.Handler.handleCallback(Handler.java:725)
04-13 13:34:20.085: E/AndroidRuntime(834): at android.os.Handler.dispatchMessage(Handler.java:92)
04-13 13:34:20.085: E/AndroidRuntime(834): at android.os.Looper.loop(Looper.java:137)
04-13 13:34:20.085: E/AndroidRuntime(834): at android.app.ActivityThread.main(ActivityThread.java:5041)
04-13 13:34:20.085: E/AndroidRuntime(834): at java.lang.reflect.Method.invokeNative(Native Method)
04-13 13:34:20.085: E/AndroidRuntime(834): at java.lang.reflect.Method.invoke(Method.java:511)
04-13 13:34:20.085: E/AndroidRuntime(834): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
04-13 13:34:20.085: E/AndroidRuntime(834): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
04-13 13:34:20.085: E/AndroidRuntime(834): at dalvik.system.NativeStart.main(Native Method)
我想在这里提到的更多事情是,当我从第二个活动返回到主要活动而不记录任何消息时,我没有设置编辑文本的内容,并且我尝试将内容发送到第一个活动,如第二部分所示它工作的代码......理想情况下它应该强制关闭自己,因为编辑文本没有数据......我不明白为什么当时它不强制关闭自己。