【发布时间】:2011-09-08 02:57:53
【问题描述】:
在活动之间传递数据有一个非常烦人的问题。
这是我用来成功地将进度条的值传递给不同活动的代码:
public void WhenClicked(View view)
{
view.clearAnimation();
Intent intent = new Intent("com.android.Test.QUESTION");
if (progressBar != null)
{
if (progressBar.getProgress() != 0)
{
intent.putExtra("ProgressBarValue", progressBar.getProgress());
}
}
startActivity(intent);
}
好的,这样就成功了。现在,当我将其更改为此时,它会爆炸:
public void WhenClicked(View view, String category)
{
view.clearAnimation();
Intent intent = new Intent("com.android.Test.QUESTION");
intent.putExtra("Category", category);
if (progressBar != null)
{
if (progressBar.getProgress() != 0)
{
intent.putExtra("ProgressBarValue", progressBar.getProgress());
}
}
startActivity(intent);
}
我不明白问题出在哪里。我什至尝试将它全部粘贴到一个捆绑包中并将捆绑包添加为额外的 - 这也让它崩溃了。也许我太愚蠢了,我只是盯着我的代码太久了,但任何帮助都会很棒!
这是我第一次使用 Android,这让我很生气!
提前谢谢各位!
【问题讨论】:
-
你能从你得到的异常中添加堆栈跟踪吗?
-
它以什么方式“炸毁”?你有一些 logcat 输出吗?
-
我真的是 Eclipse 和 Android 的新手 - 我真的不知道如何做这些事情.. 很抱歉 :( 如果这很简单,你也许可以告诉我怎么做,我'会抓住它吗?我说的炸毁是指,当我通过模拟器运行它时,只要我按下“开始”按钮,它就会抛出异常并强制关闭..
-
开始按钮是指我在 Activity 上的开始按钮,而不是实际的运行按钮。
-
whenClicked() 中的代码看起来很完美,正如您所说,添加类别后它会崩溃,我想说这可能是由您的代码的其他部分引起的,因为您更改了方法签名,发布调用此方法的代码会有所帮助。
标签: java android eclipse android-activity