我有以下代码在 facebook 上创建一个事件。它在模拟器上运行良好,但在手机中崩溃(索尼米罗):
private void createEvents()
{
try
{
mPrefs = getPreferences(MODE_PRIVATE);
String accessToken = mPrefs.getString("access_token", null);
facebookatEventCreate.setAccessToken(accessToken);
long expires = mPrefs.getLong("access_expires", 0);
if (accessToken != null)
{
facebookatEventCreate.setAccessToken(accessToken);
}
if (expires != 0)
{
facebookatEventCreate.setAccessExpires(expires);
}
if (!facebookatEventCreate.isSessionValid())
{
facebookatEventCreate.authorize(this, new String[] {
"email", "publish_stream", "create_event"
}, new DialogListener()
{
@Override
public void onCancel()
{
// Function to handle cancel event
}
@Override
public void onComplete(Bundle values)
{
// Function to handle complete event
// Edit Preferences and update facebook acess_token
SharedPreferences.Editor editor = mPrefs.edit();
editor.putString("access_token", facebookatEventCreate.getAccessToken());
editor.putLong("access_expires", facebookatEventCreate.getAccessExpires());
editor.commit();
}
@Override
public void onError(DialogError error)
{
// Function to handle error
}
@Override
public void onFacebookError(FacebookError fberror)
{
// Function to handle Facebook errors
}
});
}
//getting the event name from the text box
String eventName = txtEventName.getText().toString();
Log.d("createEvent:createEvent", "Event Name->"+ eventName);
//getting the event location from the text box
String eventLocation = txtEventLocation.getText().toString();
Log.d("createEvent:createEvents", "Event Location->"+ eventLocation);
//getting the event description from the text box
String eventDescription = txtEventDescription.getText().toString();
Log.d("createEvent:createEvents", "Event Description->"+eventDescription);
//this is the date of the event picked from the dialog
//Log.d("createEvent:createEvents", "new Time->" + startDate);
startDateAndTime = startDate + startTime;
Log.d("createEvent:createEvents", "DATE AND TIME->"+startDateAndTime);
Bundle params = new Bundle();
params.putString("name", eventName);
params.putString("start_time", startDateAndTime);
//params.putString("end_time", "2013-12-02T20:00:00+0530");
params.putString("description", eventDescription);
params.putString("location", eventLocation);
params.putString("privacy_type", "OPEN");
mAsyncRunner1.request("me/events", params, "POST", new RequestListener()
{
@Override
public void onMalformedURLException(MalformedURLException e, Object state)
{
}
@Override
public void onIOException(IOException e, Object state)
{
}
@Override
public void onFileNotFoundException(FileNotFoundException e, Object state)
{
}
@Override
public void onFacebookError(FacebookError e, Object state)
{
}
@Override
public void onComplete(String response, Object state)
{
try
{
JSONObject event = new JSONObject(response);
eventID = event.getString("id");
Log.d("createEvent:createEvent", "Event ID->" + eventID);
Log.i(response, response);
//Toast.makeText(getApplicationContext(), "New Event Created!!", Toast.LENGTH_LONG).show();
}
catch (Exception e)
{
}
}
}, null);
}
catch (Exception e)
{
}
}
在使用模拟器进行调试时,我在 logcat 上收到以下消息:
12-13 11:26:01.019: I/Adreno200-EGLSUB(6360): <ConfigWindowMatch:2081>: Format RGBA_8888.
12-13 11:26:01.029: D/memalloc(6360): /dev/pmem: Mapped buffer base:0x51832000 size:614400 offset:0 fd:67
12-13 11:26:01.179: D/memalloc(6360): /dev/pmem: Mapped buffer base:0x51b51000 size:2396160 offset:1781760 fd:70
12-13 11:26:02.259: D/memalloc(6360): /dev/pmem: Mapped buffer base:0x51e9a000 size:3010560 offset:2396160 fd:73
12-13 11:26:02.399: D/-heap(6360): GC_FOR_ALLOC freed 125K, 16% free 6562K/7775K, paused 21ms
12-13 11:26:02.499: D/-heap(6360): GC_CONCURRENT freed 3K, 8% free 15558K/16803K, paused 2ms+2ms
和这个:
12-13 11:26:17.899: E/ActivityThread(6360): Failed to find provider info for com.facebook.katana.provider.AttributionIdProvider
有了这个应用程序崩溃:
12-13 11:26:18.979: V/WebRequest(6360): WebRequest::WebRequest, setPriority = 1
12-13 11:26:19.159: E/WindowManager(6360): Activity com.hsenid.eventer.ui.createEvent has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@41b70728 that was originally added here
12-13 11:26:19.159: E/WindowManager(6360): android.view.WindowLeaked: Activity com.hsenid.eventer.ui.createEvent has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@41b70728 that was originally added here
12-13 11:26:19.159: E/WindowManager(6360): at android.view.ViewRootImpl.<init>(ViewRootImpl.java:345)
12-13 11:26:19.159: E/WindowManager(6360): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:268)
12-13 11:26:19.159: E/WindowManager(6360): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:216)
12-13 11:26:19.159: E/WindowManager(6360): at android.view.WindowManagerImpl$CompatModeWrapper.addView(WindowManagerImpl.java:141)
12-13 11:26:19.159: E/WindowManager(6360): at android.view.Window$LocalWindowManager.addView(Window.java:537)
请让我知道我应该做什么......提前谢谢你!