【问题标题】:using a textview within an intentservice android在intentservice android中使用textview
【发布时间】:2014-06-04 08:52:54
【问题描述】:

我在我的 MainActivity 中创建了一个文本视图,我需要将它传递给我的 IntentService 因为我需要在其他地方使用 MainActivity 的 textview。是否可以在 IntentService 中使用 findViewById,或者是否有一种方法可以执行类似的操作以允许在 IntentService 中使用 TextView?

谢谢

【问题讨论】:

  • 服务没有用户界面。您可以使用 Handler 或 LocalBroadCastReciever 或 EventBus 等第三方库,然后在 Activity 本身中更新 ui

标签: android textview android-intentservice


【解决方案1】:

您可以使用putExtra 将您的textview id 保存在intent 中:

Intent i1 = new Intent(ListaActivity.this, ListDetailActivity.class); 
i1.putExtra("YourKey", "your textview id".toString()); 
startActivity(i1);

要检索信息:

Intent intent = getIntent(); 
String textViewID = intent.getStringExtra("YourKey");

【讨论】:

    猜你喜欢
    • 2023-04-02
    • 1970-01-01
    • 2017-05-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多