Squall Huang
Squall Huang

Reputation: 705

Why StartActivity(intent) failed? logcat show W/ActivityThread: handleWindowVisibility: no activity for token android.os.BinderProxy@

I just want to ask why StartActivity(intent) failed? Then logcat show :

D/AddPhotosFragment: categoryDesignID: ClothingDesign
D/EGL_emulation: eglMakeCurrent: 0x7ea0c3349a00: ver 2 0 (tinfo 0x7ea19df7cea0)
W/ActivityThread: handleWindowVisibility: no activity for token android.os.BinderProxy@15c2c02
D/CategoryDetailRecyclerViewActivity: Intent:Intent {  } 
D/CategoryDetailRecyclerViewActivity: categoryDesignID: null

AddPhotosFragment.kt

//Upload images button
upload_imgs_button.setOnClickListener {
    Log.d(TAG, "uploadImgsPath: $uploadImgsPath");
    //Upload images to firebase storage
    if (uploadImgsPath != null) {

        var count = imagesList.size
        for (uriForUpload in imagesList) {
            val uri = Uri.parse(uriForUpload)
            val imgNameUUID = UUID.randomUUID().toString()
            val withAppendedPath =
                Uri.withAppendedPath(uri, imgNameUUID).toString()
            var imgFileRef = uploadImgsPath!!.child(withAppendedPath)
            imgFileRef.putFile(uri)
                .continueWithTask {
                    if (!it.isSuccessful) {
                        it.exception?.let {
                            throw it
                        }
                    }
                    imgFileRef.downloadUrl
                }.addOnCompleteListener {
                    if (it.isSuccessful) {
                        var uriForDownload = it.result.toString()
                        Log.d(TAG, "uriForDownload:$uriForDownload ");
                        downloadImagesUriList.add(uriForDownload)
                        count--
                        if (count == 0) {
                            Log.d(
                                TAG,
                                "downloadImagesUriList:$downloadImagesUriList "
                            );
                            var uuidOfGroupId = UUID.randomUUID().toString()
                            var uploadedImages = UploadedImages(
                                categoryDesignID,
                                user!!.uid,
                                downloadImagesUriList,
                                Timestamp.now(),
                                uuidOfGroupId,
                                user!!.photoUrl.toString(),
                                user!!.displayName
                            )
                            Log.d(TAG, "uploadedImages:$uploadedImages ");
                            //Save uploaded images path info to firestore
                            firestore.collection("uploadedImages")
                                .document(uuidOfGroupId)
                                .set(uploadedImages)
                                .addOnSuccessListener {
                                    Toast.makeText(
                                        context,
                                        "Upload successful",
                                        Toast.LENGTH_LONG
                                    ).show()
                                    //TODO Show RecyclerView
                                    var intent = Intent(
                                        context,
                                        CategoryDetailRecyclerViewActivity::class.java
                                    )
                                    Log.d(
                                        TAG,
                                        "categoryDesignID: ${uploadedImages.categoryDesignID}"
                                    );
                                    intent.putExtra(
                                        "categoryDesignID",
                                        uploadedImages.categoryDesignID
                                    )

                                    startActivity(intent)

                                }
                        }
                    }
                }
        }   

CategoryDetailRecyclerViewActivity.kt

class CategoryDetailRecyclerViewActivity : AppCompatActivity() {

    val TAG = CategoryDetailRecyclerViewActivity::class.java.simpleName

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_category_detail_recycler_view)

        var intent = Intent()
        Log.d(TAG, "Intent:$intent ");
        var categoryDesignID = intent.getStringExtra("categoryDesignID")
        Log.d(TAG, "categoryDesignID: $categoryDesignID");

My manifest:

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity android:name=".ui.categoryDetailRecyclerView.CategoryDetailRecyclerViewActivity"></activity>
    <activity android:name=".MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

Upvotes: 0

Views: 4294

Answers (2)

Squall Huang
Squall Huang

Reputation: 705

This problem has solved.

I later changed var intent = Intent() into var intent = getIntent(), then CategoryDetailRecyclerViewActivity can get intent.

Upvotes: 0

WarrenFaith
WarrenFaith

Reputation: 57672

I am unsure what you mean by why StartActivity(intent) failed but based on your Logcat, it prints what I would expect from the code.

First of all it doesn't fail. You see in the Log that the code inside the onCreate() is executed. So the activity is started.

D/CategoryDetailRecyclerViewActivity: Intent:Intent {  } 
D/CategoryDetailRecyclerViewActivity: categoryDesignID: null

Here you see one of the problems: Your categoryDesignID is null. That is because you are not reading it from the right place. To get the data from the intent you used to start an Activity, you should ask for the intent instead of creating a new one.

Change your onCreate code to this and is should at least log the right id value:

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_category_detail_recycler_view)

    // don't create an Intent instance, it is already available and contains what you have send via startActivity(intent)
    // var intent = Intent()
    Log.d(TAG, "Intent:$intent ");
    var categoryDesignID = intent.getStringExtra("categoryDesignID")
    Log.d(TAG, "categoryDesignID: $categoryDesignID");
}

Upvotes: 3

Related Questions