2014-01-09 81 views
0

我在我的第一个活动中实现了Google+登录,然后在另一个活动中,我需要通过按下按钮发布某些内容。第一个活动的登录完美,但我需要其他活动中的PlusClient对象,因为我需要它与PlusShare.build(...)一起发布。我怎样才能通过或构造PlusClient对象通过这两个活动?通过活动传递PlusClient对象

这里是方法的代码共享内容:

public void onGoogleButtonClick(int position) { 

    if(mPlusClient.isConnected()){ 
    Intent shareIntent = new PlusShare.Builder(this, mPlusClient) 
      .setType("text/plain") 
      .setText("Hey +"+usersInLab.get(position).getIdGoogle()+"! I'm at the JOL Lab!") 
      .getIntent(); 

    startActivityForResult(shareIntent, 0); 
    }else{ 
     runOnUiThread(new Runnable() { 

      @Override 
      public void run() { 
       Toast.makeText(getApplicationContext(), "Not logged in Google+", Toast.LENGTH_SHORT).show(); 
      } 
     }); 
    } 
} 

用朋友的ID在文本,我需要用我的PlusClient对象建立PlusShare但在这个活动我有没有PlusClient对象,因为我使用MainActivity中的所有方法(onConnected(),onConnectionFailed()...)实现了它。

回答

0

使用以下代码。它为我工作。希望这将有助于你

enter code here 
    Intent shareIntent = new PlusShare.Builder(getActivity()) 
       .setType("text/plain").setText(shareDescription) 
       .setContentUrl(Uri.parse("http://" + shareURL)).getIntent(); 
    startActivityForResult(shareIntent, 0); 

     `enter code here 
+0

感谢你的帮助,但我需要有一个朋友,他知道谷歌的ID与此调用分享讯息:usersInLab.get(位置).getIdGoogle() – Cardella