Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android activity not displaying

I have an application which uses official facebook sdk for downloading facebook albums. Recently, I updated my code to incorporate new FB android sdk 3.0.

My first activity starts FB authentication, requests friends' list and sends the graph id of the selected friend to second activity using an intent.

I have NOT made any changes to code for starting second activity but android.view.windowleaked exception occurred. So I called the progress dialog's dismiss function in the onPause, onStop functions of my first activity. Then the error disappeared.

But the second activity is still not shown foreground. Also there are no exceptions. Here is my code.

album_intent = new Intent();
album_intent.putExtra("id",graph_id);
album_intent.putExtra("name",selected_friend.toString());
//album_intent.setComponent(new ComponentName(Barebone_fbActivity.this, album_selector.class));
album_intent.setClass(this, album_selector.class);

album_intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
//Context context = getApplicationContext();
//context.startActivity(album_intent);
try
{
    getApplicationContext().startActivity(album_intent);
}
catch(ActivityNotFoundException ex)
{
ex.printStackTrace();
}

I added a toast to second activity's onCreate method. Surprisingly the toast is displayed but the activity itself is not displayed. I have also checked my manifest file and have NOT made any changes. I suspect the FB android SDK 3.0 because they have changed almost everything from login to graph api request. Please help to find the problem.

All activities in my application implements StatusCallback. Here is lifecycle methods of album_selector activity. The 'call' method of StatusCallback is lengthy so it is not included. Also the second activity extends ListActivity.

@Override
public void onCreate(Bundle savedInstanceState)
{
    //locks the screen in portrait mode
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    Toast.makeText(this, "Voila", Toast.LENGTH_SHORT).show();
    this.setVisible(true);

    dialog = ProgressDialog.show(album_selector.this, "", getText(R.string.loading));

    //pressing back button dismisses the progress dialog
    dialog.setCancelable(true);

    //get friend_name and friend_id from the intent which started this activity
    Intent starting_intent = getIntent();
    friend_id = starting_intent.getStringExtra("id");
    friend_name = starting_intent.getStringExtra("name");

    lv = getListView();

    Session currentSession = Session.getActiveSession();
    if(currentSession == null || currentSession.getState().isClosed())
    {
        Session session = Session.openActiveSession(this, true, this);
        //Session session = Session.restoreSession(this, null, this, bundle);
        currentSession = session;
    }
    if (currentSession != null && !currentSession.isOpened())
    {
        OpenRequest openRequest = new OpenRequest(this).setCallback(this);
        if(openRequest == null)
        {
            openRequest.setDefaultAudience(SessionDefaultAudience.FRIENDS);
            openRequest.setPermissions(Arrays.asList(permissions));
            openRequest.setLoginBehavior(SessionLoginBehavior.SSO_WITH_FALLBACK);
            currentSession.openForRead(openRequest);
        }
    }
    dialog.dismiss();
}

public void onActivityResult(int requestCode, int resultCode, Intent data)
{
    super.onActivityResult(requestCode, resultCode, data);
    Session.getActiveSession().onActivityResult(this, requestCode, resultCode, data);
}

protected void onStop()
{
    super.onPause();
    album_selector.this.dialog.dismiss();
}

protected void onPause()
{
    super.onPause();
    album_selector.this.dialog.dismiss();
}
like image 509
Vysakh Prem Avatar asked Jul 19 '26 10:07

Vysakh Prem


1 Answers

I had a similar problem where the activity was loading and running but it would not be visible.

The problem was that in the AndroidManifest.XML the activity had a theme defined as NoDisplay:

android:theme="@android:style/Theme.NoDisplay"

Removing the above attribute from the activity made it visible again.

like image 136
swbandit Avatar answered Jul 22 '26 00:07

swbandit