2014-12-02 70 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"))); 

由於傑米·查普曼爲使其可用。