the MainActivity show the up icon(the left-facing caret) - android

I am working under an android application which I want to provide the Up Navigation, follow the guide, I made the following configuration:
<activity
android:name=".ui.MainActivity"
android:launchMode="singleTask" android:theme="#style/OverlayActionBarTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
<action android:name="android.intent.action.SEARCH"/>
</intent-filter>
<meta-data
android:name="android.app.searchable"
android:resource="#xml/searchable"/>
</activity>
<activity
android:name=".ui.RouteActivity"
android:parentActivityName=".ui.MainActivity">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".ui.MainActivity"/>
</activity>
<activity
android:name=".ui.SearchPoiActivity" android:parentActivityName=".ui.MainActivity">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".ui.MainActivity"/>
</activity>
<activity
android:name=".ui.PoiListActivity" android:parentActivityName=".ui.MainActivity">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".ui.MainActivity"/>
</activity>
However I have to questions here:
1 The repeat codes
As you can see I have to add the following xml for each activity, is it possible to declare it once?
android:parentActivityName=".ui.MainActivity">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".ui.MainActivity"/>
2 The main activity of my application .ui.MainActivity have the up icon !
Tha's to say even I enter my application the first time and at the MainActivity, the left-facing caret is visible. I do not think this is normal.
Then I wonder does I miss anything?

Related

Activities' stack (after exit the app, the system clears stack if launchMode="singleInstance")

I don't understant why is this happend: I need to create every Activity in single instance, so I put android:launchMode="singleInstance" in Manifest. But when I push 'Home' on the device and open it again the system clears the stack and opens the root Activity, not the last one that was open. How can I keep the last open Activity for the user but keep singleInstance in Manifest?
EDIT:
Manifest
...
<application
...>
<activity
android:name=".ui.login.LoginActivity"
android:launchMode="singleInstance"
android:screenOrientation="portrait"/>
<activity
android:name=".ui.activity.MainActivity"
android:label="${app_title_constant}"
android:launchMode="singleInstance"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
<intent-filter>
<data android:scheme="${scheme}"/>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
</intent-filter>
</activity>
<activity
android:name=".ui.more.service.ScannerActivity"
android:screenOrientation="portrait"
android:theme="#style/AppTheme"/>
<activity
android:name=".ui.activity.CardsListForSendActivity"
android:launchMode="singleInstance"
android:screenOrientation="portrait"/>
<activity
android:name=".ui.activity.CountriesActivity"
android:launchMode="singleInstance"
android:screenOrientation="portrait"/>
<activity
android:name=".ui.activity.StepperCardPurchaseActivity"
android:launchMode="singleInstance"
android:screenOrientation="portrait"/>
<service
android:name=".service.CacheContactsIntentService"
android:exported="false"/>
<service
android:name=".managers.push.PushNotificationExtenderService"
android:exported="false">
<intent-filter>
<action android:name="com.onesignal.NotificationExtender"/>
</intent-filter>
</service>
<receiver
android:name=".managers.push.PushBroadcastReceiver"
android:enabled="true">
</receiver>
</application>
</manifest>
Do not use launchMode="singleInstance". This is not necessary, and actually isn't working for you anyway. Normally, specifying "singleInstance" will cause each and every Activity to be launched into its own separate task. This, however, won't happen in your case because you have not specified "taskAffinity" in the manifest. Since all activities, by default, have the same task affinity, they will all end up in the same task (even though you specified "singleInstance" launch mode).
Remove all the launchMode specifiers and try again.
The standard behaviour of Android is to return the user to the task stack (exactly as he left it) when an App is brought from the oforeground to the background (after pressing the HOME button and returning to the app).

android up button is not working as expected

I'm followed https://developer.android.com/training/appbar/up-action.html to add an up button for the app bar.
my manifest is
<activity
android:name=".activity.MyDiaryAct"
android:label="#string/title_activity_my_diary"
android:theme="#style/Theme.AppCompat.Light.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".activity.PageListAct"
android:label="#string/title_page_list"
android:theme="#style/AppTheme.NoActionBar"
android:parentActivityName=".activity.MyDiaryAct">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="activity.MyDiaryAct" />
</activity>
<activity
android:name=".activity.PageAct"
android:label="#string/title_page_name"
android:screenOrientation="portrait"
android:theme="#style/AppTheme.NoActionBar"
android:parentActivityName=".activity.PageListAct" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="activity.PageListAct" />
</activity>
I started PageAct from MyDiaryAct and click up button. It returned to myDiaryAct but I'm expecting PageListAct.
My codes at PageAct
android.support.v7.app.ActionBar ab = getSupportActionBar();
ab.setTitle(page.getName());
ab.setDisplayHomeAsUpEnabled(true);
What am I missing? I wish not to add codes at onOptionsItemSelected(). Thanks!
PS: I'm using targetSdkVersion 23.
UPDATE: while the possible duplicate post provides useful information and direction to solve my problem but the complete understanding and solution found at here.
https://developer.android.com/training/implementing-navigation/ancestral.html
In short, the parent has to be in backs tack else I need to create it manually.

android search view on another Activity

I'm Creating a Search View Sample Project;
I have 3 Activities:
MainActivity(Direct you to search Activity)
SearchActivity(You can see search View and type whatever you want)
SearchResultActivity(Will Process your Search request)
and in Manifest file I have
<activity
android:name="com.example.searchsample.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".SearchActivity">
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
<meta-data android:name="android.app.searchable"
android:resource="#xml/searchable" />
</activity>
<activity android:name=".SearchResultActivity">
</activity>
if I press search button; I can see the new SearchActivity Opens ;
if I move the intent-filter Part from .SearchActivity to .SearchResultActivity; I no longer can Search anything; (Because the .SearchResultActivity never run)
how can I solve this Problem;
I want, when I Press the search button, see result on .SearchResultActivity

Android Manifest File Not Picking Up Default Launch Activity

If on run/debug configuration, if I specify a launch activity, then my app runs fine, but when I select 'Launch Default Activity' I get "No Launcher activity found!" error from android adb despite the fact that I have specified the launch activity in my manifest file. I'm using android 2.1.
I've tried refreshing the file/project, clean and rebuild, deleting the file and re-writing it, creating a new project and copy/pasting all the code across and doing Android Tools -> Fix Project Properties. I've tried Android Tools-> Rename Application Package, which prompts me to update the project launch configuration (to which I say yes, but it still doesn't fix the problem).
I've also tried different devices. My Home activity extends another activity and is in its own Home.java file in my src folder. This is what my manifest file looks like:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.geogreenweb.localvore"
android:versionCode="1"
android:versionName="1.0">
<application
android:icon="#drawable/icon"
android:label="#string/general_app_name"
android:debuggable="true">
<meta-data android:name="android.app.default_searchable"
android:value=".localvorebeta6" />
<activity android:name="com.geogreenweb.localvore.Home"
android:label="#string/general_app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
<meta-data android:name="android.app.searchable"
android:resource="#xml/searchable"/>
</activity>
<activity android:name="com.geogreenweb.localvore.Quit"
android:label="Quit">
</activity>
<activity android:name="com.geogreenweb.localvore.InSeason"
android:label="In Season">
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
<meta-data android:name="android.app.searchable"
android:resource="#xml/searchable"/>
</activity>
<activity android:name="com.geogreenweb.localvore.List"
android:label="A - Z">
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
<meta-data android:name="android.app.searchable"
android:resource="#xml/searchable"/>
</activity>
<activity android:name="com.geogreenweb.localvore.Local"
android:label="Local"
android:configChanges="orientation"
android:windowSoftInputMode="stateHidden">
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
<meta-data android:name="android.app.searchable"
android:resource="#xml/searchable"/>
</activity>
<activity android:name="com.geogreenweb.localvore.Details"
android:label="Details">
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
<meta-data android:name="android.app.searchable"
android:resource="#xml/searchable"/>
</activity>
<activity android:name="com.geogreenweb.localvore.Search"
android:label="Search">
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
<meta-data android:name="android.app.searchable"
android:resource="#xml/searchable"/>
</activity>
<activity android:name="com.geogreenweb.localvore.Map"
android:label="Map"
android:windowSoftInputMode="stateHidden">
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
<meta-data android:name="android.app.searchable"
android:resource="#xml/searchable"/>
</activity>
<activity android:name="com.geogreenweb.localvore.Help"
android:label="Help">
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
<meta-data android:name="android.app.searchable"
android:resource="#xml/searchable"/>
</activity>
</application>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-sdk android:minSdkVersion="7" />
</manifest>
UPDATE: I changed one of the activity labels, and the different label appears in the app, so the changes to the manifest file are being picked up, but still I get the No Launch Activity error
UPDATE 2: I managed to solve the problem by creating a new project in the end, but only if I select the option to create an activity when making the new project, then copy/paste in the rest of the stuff into the project
if you remove the :
<action android:name="android.intent.action.SEARCH" />
it will launch normally.
i don't know why .. it just worked for me. i'm still searching why?!!
UPDATE 1:
i found this:
No Launcher activity found, despite being declared in manifest.xml
still don't know why? .. still searching for it.
UPDATE 2: GOT IT!
http://developer.android.com/guide/topics/intents/intents-filters.html
A filter has fields that parallel the action, data, and category fields of an Intent object. An implicit intent is tested against the filter in all three areas. To be delivered to the component that owns the filter, it must pass all three tests. If it fails even one of them, the Android system won't deliver it to the component — at least not on the basis of that filter. However, since a component can have multiple intent filters, an intent that does not pass through one of a component's filters might make it through on another.
in our case this means that the system sends an intent with the MAIN action and LAUNCH category. it finds an with the following:
MAIN action ..............[ pass ]
LAUNCH category .... [ pass ]
SEARCH action .........[ fail ]
but .. if you put the SEARCH action in another , the containing the MAIN and LAUNCHER criteria passes.
The only thing I can think of is the lines
<activity android:name="com.geogreenweb.localvore.Home"
Try using just
<activity android:name=".Home"
instead
Try adding the following to your main launcher Activity right next to the launcher category element.
<category android:name="android.intent.category.DEFAULT"/>

How to add quick search box to our application?

How to add quick search box (QSB) to our application?
Check this page on more info about the QSB in android.
and add this to your activity in the manifest
<activity android:name=".MyActivity" >
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
<meta-data android:name="android.app.searchable"
android:resource="#xml/searchable"/>
</activity>

Categories

Resources