Vysakh Prem
Vysakh Prem

Reputation: 93

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();
}

Upvotes: 3

Views: 9044

Answers (6)

I had a similar problem where the second activity was not shown. The toast given in the second activity was displayed !

this is a section of code of second activity.

<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".DisplayAge">

After reading this post I realised that the line

http://schemas.android.com/apk/res-auto

was displayed in gray whereas the other schema links were shown in green. So I copied this part again from the main activity xml.

 xmlns:app="http://schemas.android.com/apk/res-auto"

After this the line starting showing in green and on running the app the second activity was displayed.

Upvotes: 0

hem1t
hem1t

Reputation: 1

.java file and .xml file, try giving these files the same name.

Upvotes: 0

Christoforos Seas
Christoforos Seas

Reputation: 96

I had the same problem, turned out to be autofills. Remove any autofills

 android:autofillHints=""

Upvotes: 0

jeet.chanchawat
jeet.chanchawat

Reputation: 2595

For future users : If child layout is having ConstraintLayout and parent layout is having RelativeLayout / LinearLayout then the child will not render. Check if that is your case.

Upvotes: 0

Darshan Thakral
Darshan Thakral

Reputation: 1

See if your child activity which you want to intent is within another package created by you. If it is, that's the reason it is not recognizing your activity. Refract it out to that location where your parent activity is. And that it.

Upvotes: 0

swbandit
swbandit

Reputation: 2006

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.

Upvotes: 2

Related Questions