首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >为什么StartActivity(意图)失败?logcat显示W/ActivityThread: handleWindowVisibility:没有令牌android.os.BinderProxy@的活动

为什么StartActivity(意图)失败?logcat显示W/ActivityThread: handleWindowVisibility:没有令牌android.os.BinderProxy@的活动
EN

Stack Overflow用户
提问于 2020-01-10 08:51:20
回答 2查看 4.1K关注 0票数 0

我只想问为什么StartActivity(意图)失败了?然后logcat显示:

代码语言:javascript
运行
复制
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

代码语言:javascript
运行
复制
//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

代码语言:javascript
运行
复制
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");

我的舱单:

代码语言:javascript
运行
复制
<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>

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2020-01-10 09:20:10

我不知道您所说的why StartActivity(intent) failed是什么意思,但是基于您的Logcat,它输出了我对代码的期望。

首先,它不会失败。您可以在日志中看到onCreate()中的代码被执行。活动就开始了。

代码语言:javascript
运行
复制
D/CategoryDetailRecyclerViewActivity: Intent:Intent {  } 
D/CategoryDetailRecyclerViewActivity: categoryDesignID: null

这里您看到了一个问题:您的categoryDesignID是空的。那是因为你没有从正确的地方阅读它。要从启动某个活动的意图中获取数据,您应该请求该意图,而不是创建一个新的意图。

将您的onCreate代码更改为此,至少应该记录正确的id值:

代码语言:javascript
运行
复制
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");
}
票数 3
EN

Stack Overflow用户

发布于 2020-01-10 09:55:52

这个问题已经解决了。

后来,我将var intent = Intent()更改为var intent = getIntent(),然后CategoryDetailRecyclerViewActivity可以获得意图。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59678253

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档