2014-12-02 72 views
2

所以我有一个ParseQueryAdapter,我试图使用共享意图方法。我将它带到了共享意图函数的位置,但它只发送额外的文本而不是解析对象。我尝试使用Parse查询,但没有奏效。任何人有关于如何检索解析对象的想法。这里是我下面的代码:将分析对象添加到意图

//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))); 
     } 
    }); 

回答

2

为此,你需要得到的parseObject ID,将其传递给意图,然后在接收到的parseObject ID,从剖析数据库得到它。

+0

我想使用ParseObject,但我怎么能把它传递给意图? – user3900101 2014-12-02 23:06:32

+0

尝试获取解析对象的id,这就是全部,并将其设置为额外字段,并在您收到意图时获取它 – Kiloreux 2014-12-03 13:47:38

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(); 
} 
+0

它没有工作,Intent显示EXTRA_TEXT字符串不是标题中的字符串。 – user3900101 2014-12-02 23:12:24

+0

@ user3900101那么你真的想通过意图传递什么? 'ParseObject po = query.get(“title”);'? – icylogic 2014-12-03 00:25:57

+0

我想从ListActivity中的项目的字符串通过意图传递。所以我需要弄清楚如何将解析项中加载的字符串作为文本传递给intent。 – user3900101 2014-12-03 00:51:44

0

虽然@ Kiloreux的解决方案是在大多数情况下,正确的,有时你已经叫你需要的,不想浪费拨打另一个电话的数据,在这种情况下:

这是一个简单的分析对象的包装,使其能够以意图传递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"))); 

由于杰米·查普曼为使其可用。