将Parse Object添加到intent

时间:2014-12-02 18:02:28

标签: android android-intent parse-platform

所以我有一个ParseQueryAdapter,我正在尝试使用共享意图方法。我得到了共享意图的功能,但它只发送额外的文本而不是parse对象。我尝试使用Parse Query但是没有用。任何想知道如何检索解析对象的人。以下是我的代码:

//Set share button to
    ImageButton shareButton = (ImageButton) v.findViewById (R.id.shareButton);
    shareButton.setClickable (true);
    shareButton.setOnClickListener (new View.OnClickListener () {
        @Override
        public void onClick(View v) {

            ParseQuery<ParseObject> query = ParseQuery.getQuery("Ads");
            try {
                query.get ("title").toString ();
            } catch (ParseException e) {
                e.printStackTrace ();
            }

            Bundle bundle = new Bundle ();
            bundle.get ("title");

            Intent sendIntent = new Intent (getContext (), ContentFeed.class);
            sendIntent.setAction (Intent.ACTION_SEND);
            sendIntent.putExtra (Intent.EXTRA_TEXT, "This is my text to send.");
            sendIntent.putExtras (bundle);
            sendIntent.setType ("text/plain");
            getContext ().startActivity (Intent.createChooser (sendIntent, getContext ().getText (R.string.send_to)));
        }
    });

3 个答案:

答案 0 :(得分:2)

为此,您需要获取ParseObject ID,将其传递给intent,然后在收到ParseObject ID后,从Parse数据库中获取它。

答案 1 :(得分:0)

Bundle bundle = new Bundle ();
bundle.get ("title");

你刚刚获得一个新的捆绑包,为什么要使用get?

可能像

 Bundle bundle = new Bundle ();
 try {
     bundle.putCharSequence("title", query.get ("title").toString ());
 } catch (ParseException e) {
     e.printStackTrace ();
 }

答案 2 :(得分:0)

尽管@ Kiloreux的解决方案在大多数情况下是正确的,但有时您已经调用了所需的数据,并且不想浪费地再次拨打电话,在这种情况下:

这是一个简单的Parse对象的包装器,它允许它在一个intent ParseProxyObject中传递。

用法:

// --- Sending ---
ParseProxyObject ppo = new ParseProxyObject(myParseObject);

Intent intent = new Intent(MyActivity.class);
intent.putExtra("parseObject", ppo);

// --- Receiving ---
Intent intent = getIntent();
ParseProxyObject ppo = (ParseProxyObject)intent.getSerializableExtra("parseObject");
Log.v("Test", String.format("Proxy object name: %s", ppo.getString("name")));

感谢Jamie Chapman让它可用。

相关问题