0

我想知道如何从 a 传递或获取值Toast,以便我可以在我的TextView.

编辑

这部分 mycode 正在服务中

public void onStart(Intent i, int stID){
   super.onStart(i, stID);
   Toast.makeText(getApplicationContext(), "Horas", Toast.LENGTH_LONG).show();
}

以下代码是我的主要活动的一部分

protected void onCreate(Bundle savedInstanceState){
   super.onCreate(savedInstanceState);
   setContentView(R.layout.activity_main);
   //this code to call the service
   startService(new Intent (this, MyService.class));
}

所以我可以在我的服务或我的主要活动中添加什么,让我可以在 textview 中获取和显示消息有人可以帮我解决这个问题吗?

4

2 回答 2

1

尝试这个

static String toast_msg;
  public void onStart(Intent i, int stID){
  toast_msg="Horas"; 
   super.onStart(i, stID);
   Toast.makeText(getApplicationContext(), toast_msg, Toast.LENGTH_LONG).show();
}

也添加这行代码

TextView Text = (TextView) findViewById(R.id.input);
Text.setText(MyService.toast_msg)
于 2013-07-12T05:46:37.900 回答
1

将 toast 消息存储在字符串变量中并从活动中访问此变量

  String toast_msg;
  public void onStart(Intent i, int stID){
  super.onStart(i, stID);
  toast_msg="Horas";
   Toast.makeText(getApplicationContext(), toast_msg, Toast.LENGTH_LONG).show();
}

在活动中创建服务类对象并访问 toast_msg

于 2013-07-12T04:25:23.187 回答