在函数SetIntent中,我已经初始化了对象inputIntent,inputIntent和emailIntent都是同一个指针。
为什么 obj emailIntent 为空并显示“错误”?
Intent emailIntent=null;
Utility.SetIntent(getApplicationContext(),emailIntent, myindex);
if (emailIntent==null){
Toast.makeText(getApplicationContext(),"Error" ,Toast.LENGTH_SHORT).show();
}
public static final String MyIntent=Intent.ACTION_SEND_MULTIPLE;
public static final String MySetType="image/*";
public static void SetIntent(Context mycontext, Intent inputIntent, int index) {
inputIntent = new Intent(MyIntent);
inputIntent.setType(MySetType);
PackageManager pm = mycontext.getPackageManager();
List<ResolveInfo> emailers = pm.queryIntentActivities(inputIntent, 0);
int dbIndex=index-1;
if (
((dbIndex)<= (emailers.size()-1))
&&
((dbIndex)>=0)
)
{
ResolveInfo r = emailers.get(dbIndex);
inputIntent.setClassName(r.activityInfo.packageName, r.activityInfo.name);
Toast.makeText(mycontext,r.activityInfo.packageName+" "+r.activityInfo.name ,Toast.LENGTH_SHORT).show();
}
}