novoda / simple-chrome-custom-tabs

Easy integration of Chrome Custom Tabs into your project. Just connect it to your activity, and navigate to the external website styling your tab as you wish.
Other
129 stars 18 forks source link

Weird behavior on back/close pressed #26

Closed hamen closed 8 years ago

hamen commented 8 years ago

Hi all and thank you for the useful library.

I'm seeing a weird behavior when I try to go back to the app from the CustomTab. When I tap back or the X symbol, the CustomTab goes back for a moment to my app and then it jumps to Chrome. This is not happening if there is no Chrome instance in the recent apps.

My Activity contains this configuration:

    val fallback = NavigationFallback { url ->
        Toast.makeText(applicationContext, "CustomTabs not supported", Toast.LENGTH_SHORT).show()
        val intent = Intent(Intent.ACTION_VIEW).setData(url).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
        startActivity(intent)
    }
    val customizer = IntentCustomizer { simpleChromeCustomTabsIntentBuilder ->
        val icon = BitmapFactory.decodeResource(resources, android.R.drawable.ic_menu_share)
        val shareLabel = getString(R.string.share_menu_item)
        val actionIntent = Intent(this.applicationContext, ShareBroadcastReceiver::class.java)
        val pendingIntent = PendingIntent.getBroadcast(applicationContext, 0, actionIntent, 0);

        simpleChromeCustomTabsIntentBuilder
            .withUrlBarHiding()
            .withDefaultShareMenuItem()
            .withToolbarColor(ContextCompat.getColor(this, R.color.primary))
            .withActionButton(icon, shareLabel, pendingIntent, false)
    }
    override fun openUrl(url: Uri) {
        SimpleChromeCustomTabs.getInstance()
            .withFallback(fallback)
            .withIntentCustomizer(customizer)
            .navigateTo(url, this)
    }

Am I missing something? Thank you.

juankysoriano commented 8 years ago

Hello Ivan,

Thank you for your message.

I have been trying to replicate the issue on the extended demo which is provided on this repository with no luck. I have also applied the same configuration as you posted here in the demo, again; no luck.

I am pretty sure there is nothing wrong in your configuration and the error is lying somewhere else.

Are you able to provide more details on how does your activity look?

Are you overriding pending transitions? Is there any flag associated to the activity? (e.g flag_activity_no_history).

When you say ( goes back for a moment ) is onResume actually being called?

I am sorry I cannot help with more information.

Could you also try a raw implementation of ChromeCustomTabs ? (without the usage of this library). The intention is to determine wether or not we actually have a problem in the library, otherwise probably we should open an issue on ChromeCustomTabs repository.

Good luck, let us know if you have more details.

hamen commented 8 years ago

Hi Jaun and thank you for your reply.

I replicated the issue with a native implementation, too, so I moved my focus elsewhere. Your hint about the flags made me check the AndroidManifest and BAM! For some obscure reason the Activity was marked as singleInstance. I removed it and now everything is working as expected.

Tricky scenario indeed, but I'm glad we sorted it out!

Thank you again for your support!

juankysoriano commented 8 years ago

I am glad you solved this!

Can you open an issue on the google's repo about the problems with singleInstance? I would do it myself but I don't want to steal you the credit 😉 .

Then I would be feel better about closing this issue and referring people to the one on the Google's repo instead.

Regards.

hamen commented 8 years ago

I opened this: https://code.google.com/p/android/issues/detail?id=215375 hoping it's the right place.

If it's OK, we can close this issue, completely unrelated to your library 😬

Thanks again.