Velvet Star Monitor

Standout celebrity highlights with iconic style.

general

How to use onNewIntent() in AppCompatActivity?

Writer Sebastian Wright

I have Main Activity (A) with searchView which goes to another SearchResultActivity (B1) which shows search results.

I want to have searchView in this second Activity too, so if user wants to write another request, he doesn't have to go back. It means when user enters request from SearchResultActivity, another instance of SearchResultActivity (B2) is fired.

After that, if user presses up button on toolbar, it goes back to activity A, as it should, because A is specified as B's parent. But the problem is, when you press back button from B2, it goes back to B1, instead of A.

I read this article, where author explains that you shouldn't create new instances of the same activity, instead flag the activity as

android:launchMode="singleTop" 

on manifest and use onNewIntent() method to reuse the same activity. It's exactly what I need.

But I can't override this onNewIntent() method, because apparently it's not present in AppCompatActivity, which I'm using. Is there any way to use onNewIntent() with AppCompatActivity? Or it works only on Activity?

1 Answer

But I can't override this onNewIntent() method, because apparently it's not present in AppCompatActivity

AppCompatActivity is a descendant of FragmentActivity, which has protected method onNewIntent().

Double check your imports.

2

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy