通过意图传递构造的数据,而不是

编程入门 行业动态 更新时间:2024-10-07 04:28:57
本文介绍了通过意图传递构造的数据,而不是的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

已经开发了许多桌面GUI程序(从Xt的Qt的,Java的AWT / SWT / Swing的,等等),我真的觉得很难习惯到Android。

Having developed many desktop GUI apps (from Xt to Qt, Java Awt/Swt/Swing, etc) I really find it difficult to get used to Android.

假设我有它通过意向机制明确要求DetailedView如下图所示的活动的MainView类:

Suppose I have the MainView Activity class which explicitly calls DetailedView via intent mechanism as shown next:

  • 由于一个Activity类通过的onCreate()实例化我怎么 定制呢? (无构造函数,只 通过意图传递数据!)

  • Since an Activity class is instantiated via onCreate() how do I customize it? (No constructor, only pass data through intent!)

有没有办法让在DetailedView实例的引用 MainActivity?

Is there a way to get a reference for the DetailedView instance in MainActivity?

有没有办法让在MainActivity实例的引用 DetailedView?

Is there a way to get a reference for the MainActivity instance in DetailedView?

如何通过引用前端到DetailedView类? Intent.putExtras()只允许 某些数据类型传递给 意图接收器类。

How can I pass the reference to FrontEnd to the DetailedView class? Intent.putExtras() allows only for certain data types to pass to the intent receiver class.

MainActivity { ... FrontEnd fe; ... public void onCreate(Bundle savedInstanceState) { ... Intent myIntent = new Intent(this, DetailedView.class); ... } protected void onListItemClick(ListView l, View v, int position, long id) { ... startActivityForResult(myIntent,..); ... }

}

}

推荐答案

我经常欺骗和使用静态'的getInstance呼吁活动和观点之间的通信。这个工作,只要他们都在同一个进程内,而我还没有有一个数据访问失败...但我敢肯定,这只是一个时间的问题。如果你正在寻找一个哈克快速修复,这可能是它,否则,您必须通过意图传递数据。

I frequently cheat and use static 'getInstance' calls to communicate between Activities and views. This works as long as they're both in the same proc, and I've yet to have a data access failure...but I'm sure it's only a matter of time...IF you're looking for a hacky quick fix this could be it, otherwise you have to pass data through intents.

更多推荐

通过意图传递构造的数据,而不是

本文发布于:2023-11-28 06:24:34,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1641283.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:意图   而不是   数据

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!