Parent Acitivity's status not kept when backing from child activity - android-activity

In AndroidManifext.xml, I have :
<activity
android:name=".mypackage.ChildActivity"
android:label="Child"
android:parentActivityName=".mypackage.ParentActivity"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateHidden|adjustResize">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".view.activities.ParentActivity" />
</activity>
Inside ParentActivity, I have a few fragements, A, B, C. At fragment C, I launch ChildActivity when clicking a button. When backing to ParentActivity, I am not landing on Fragment C, but Fragment A. It appears that ParentActivity is relaunched or initialized again.
In ChildActivity, I have:
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
As a comparison, I also tried to replace ChildActivity with a Fragment D and backing from fragment D correctly lands on fragment C.
Where did I miss for the ChildActivity implementation?
Edited:
Just noticed that when clicking "Back" button on device, it properly backs to Fragment C of ParentActivity, but if hitting the "<" button at the left top corner in Child Activity, that's where issue arises.
Thanks in advance!
Shawn

Remove the mentioning parent from your childActivity. Like below. Because android already maintains the stack of navigations
<activity
android:name=".mypackage.ChildActivity"
android:label="Child"
android:parentActivityName=".mypackage.ParentActivity"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateHidden|adjustResize">
</activity>

Related

can not return to parent activity from child activity opened by menu in Android App

manifest:
<activity
android:name=".SettingsActivity"
android:parentActivityName="com.boropost.app.MainActivity" />
<activity
android:name=".FindActivity"
android:parentActivityName="com.boropost.app.MainActivity" />
menu:
<item
android:id="#+id/action_settings"
app:showAsAction="never"/>
<item
android:id="#+id/action_find"
app:showAsAction="always"/>
In my case, the child SettingsActivity is opened via a menu item that is not showed on the action bar. Clicking the back button does not return to the parent MainActivity. The onActivityCreated in MainActivity is not triggered neither, however the child FindActivity that is opened via a menu item that is showed on the action bar does not have this issue.
Please add below lines on onCrate() method
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
And Add below method in your child SettingsActivity
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
finish();
break;
}
return true;
}

Cannot start activity from Push notification

I want to start activities when users click on push notifications. It works fine for activity A, but does not work for another activity B, it does not fully work. What happened to activity B is that if the app is not running, clicking on the push notification will correctly start activity B. However, if the app is already running, clicking on the push notification just open the current screen.
Here is how I set up the push notification:
Intent rewardsIntent = new Intent(this, ActivityRewards.class);
rewardsIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
NotificationUtils.createNotification(this, R.string.reward_notification, getResources().getString(R.string.reward_notification), "You have been rewarded", rewardsIntent);
And the static method in NotificationUtils to create the Push Notification:
public static void createNotification(Context context, int notificationId, String title, String text, Intent resultIntent) {
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(context)
.setSmallIcon(R.drawable.ico_launcher)
.setContentTitle(title)
.setContentText(text);
PendingIntent resultPendingIntent =
PendingIntent.getActivity(
context,
0,
resultIntent,
PendingIntent.FLAG_UPDATE_CURRENT
);
mBuilder.setContentIntent(resultPendingIntent);
mBuilder.setAutoCancel(true);
mBuilder.setOngoing(true);
NotificationManager mNotificationManager =
(NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(notificationId, mBuilder.build());
}
In AndroidManifest.xml, I declared the activity as follows:
<activity android:name=".ActivityRewards"
android:label="#string/my_rewards"
android:exported="true">
</activity>
This has puzzled me for few days. Any help would be very much appreciated. Thanks.
I managed to make this work by adding launchMode declaration for ActivityRewards as below:
<activity android:name=".ActivityRewards"
android:label="#string/my_rewards"
android:launchMode="singleTask"
android:exported="true">

How to remove views from Windows-->Show View list?

I have view which I am setting permanently on my perspective.
This view can not be closed and can not be opened from Windows --> show views
I struct to remove View from Windows --> view list.
How would I achieve this?
I tried your solution it is doing the things but it is also removing the view from perspective. Below are the steps I followed..
I have added the following view in plugin.XML
<view
allowMultiple="false"
category="org.view.ui.IDECategory"
class="org.view.ui.BannerInformationView"
id="org.view.ui.BannerInformationView"
name="BannerInfo"
restorable="true">
</view>
After this I have added this view in my Perspective
public void defineLayout( IPageLayout layout )
{
layout.setEditorAreaVisible( true );
layout.addStandaloneView( BANNER_INFO_VIEW_ID, false, IPageLayout.TOP, 0.03f, layout.getEditorArea() );
IViewLayout viewLayout = layout.getViewLayout( BANNER_INFO_VIEW_ID );
viewLayout.setMoveable( false );
}
Now I have added the activity to hide my view name from show view menu
<extension point="org.eclipse.ui.activities">
<activity
id="activity.ide"
name="ide">
</activity>
<activityPatternBinding
activityId="activity.ide"
isEqualityPattern="true"
pattern="org.view.ui.IDECategory.pluginid/org.view.ui.BannerInformationView">
</activityPatternBinding>
</extension>
Now my problem is, along with hiding the view entry from window -> show view, it is also hiding the view from my perspective.
I want to hide the only entry from show view so that user can not do anything with it, but it should be always visible in my perspective.
The view list is filtered by the activities list. So you can define an activity to suppress the view:
<extension point="org.eclipse.ui.activities">
<activity id="activity.id" name="Name">
</activity>
<activityPatternBinding
activityId="activity.id"
isEqualityPattern="true"
pattern="plugin.id/view.id">
</activityPatternBinding>
</extension>
Note: The pattern value is 'contributing plugin id / view id', a common mistake is leaving out the plugin id.

Actionbar up navigation with fragment and activity

I'm going to use home button (Action bar App icon) as back button. I got it to work but not in the way i intended.
My MainActivity is an activity which holds (1) a drawer that shows a list of categories. And a Fragment that displays a list of items in the category chosen in the drawer.
when a item in the list is clicked, a new DetailActivity is started to show the details.
here starts the problem:
From the DetailActivity when i press Back button, it returns to the MainActivity as it was before clicking the item to show details. That is what I expect. However, when use home button as Up navigation, it starts the MainActivity as if I opened the app again. Not showing the list that was previously being shown.
I read in developer documents that for fragments I have to use: .add(detailFragment, "detail") And .addToBackStack() then commit.
But what am I suppose to add in add(---,"---"). And then how should I use it?!
this is my codes:
the method is the MainActivity that shows the content:
public void refreshDisplay(Context context, View view, String category, int i) {
List<Lesson> lessonByCategory = datasource.findByCategory(category, i);
final ListView lv = (ListView) view.findViewById(R.id.listView);
final ArrayAdapter<Lesson> adapter = new LessonListAdapter(context, lessonByCategory);
lv.setAdapter(adapter);
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick (AdapterView<?> parent, View view, int position, long id) {
Log.i(LOGTAG, "onListItemClick called");
ArrayAdapter<Lesson> m_adapter = adapter;
// get the Lesson object for the clicked row
Lesson lesson = m_adapter.getItem(position);
Intent intent = new Intent(MainActivity.this, LessonDetailActivity.class);
intent.putExtra(".model.Lesson", lesson);
intent.putExtra("isStared", isStared);
startActivityForResult(intent, LESSON_DETAIL_ACTIVITY);
}
});
}
In my LESSON_DETAIL_ACTIVITY that shows the detail content I have this code to enable up navigation for home button:
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
// I have some other cases here
case android.R.id.home:
NavUtils.navigateUpFromSameTask(this);
return true;
}
return super.onOptionsItemSelected(item);
}
And finally in the Manifest I used the code below to introduce MainActivity as the parrent of LessonDetailActivity:
<activity
android:name=".LessonDetailActivity">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.example.MainActivity" />
</activity>
I want the Home button as up navigation to behave like back button so that when its clicked it takes me to the MainActivity as it was before opening the LessonDetailActivity. The code above doesn't do that and every time I press Home in the action bar it starts the MainActivity from scratch.
Could anyone help me with this please?
I also should say that I'm new so I'd appreciate it if the answers were detailed.

Android Custom Keyboard Implementation

I am developing Android custom keyboard. I imported android.view.inputmethod.InputMethodSubtype in my code while doing this I am getting an error message like this imported one cannot be resolved. Is there any eclipse plugin I need to install, as per my knowledge Android version above 1.6 will support IMF.
The question is very old but I am answering it as it might help another user who sees this.
OP asked if there is any plugin for Eclipse to install to resolve the issue but now we have Android Studio.
For those who want to implement Android Custom Keyboard:
First, download Google sample project for Android Custom Keyboard to start with.
There are three important features to decide which one you want: 1) theme (custom layout), 2) subtype and 3) emoticons.
For themes/ layouts: Create layout files. See the example code below:
<com.domain.keyboard.android.LatinKeyboardView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/keyboard"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#drawable/kb_bg_9"
android:keyBackground="#drawable/key_bg_fill_white"
android:keyPreviewLayout="#layout/key_preview_layout"
android:keyPreviewOffset="#dimen/keyPreviewOffset"
android:keyTextColor="#color/white"
android:popupLayout="#layout/keyboard_popup_layout" />
And use the following code in SoftKeyboard.java:
#Override
public View onCreateInputView() {
// Set custom theme to input view.
int themeLayout = sharedPreferences.getInt(THEME_KEY, R.layout.input_1);
mInputView = (LatinKeyboardView) getLayoutInflater().inflate(
themeLayout, null);
mInputView.setOnKeyboardActionListener(this);
// Close popup keyboard when screen is touched, if it's showing
mInputView.setOnTouchListener(new View.OnTouchListener() {
#Override
public boolean onTouch(View view, MotionEvent motionEvent) {
if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
mInputView.closing();
}
return false;
}
});
// Apply the selected keyboard to the input view.
setLatinKeyboard(getSelectedSubtype());
return mInputView;
}
For subtype: Create a copy of qwerty.xml and edit it to replace the keys. Create another instance of LatinKeyboard in SoftKeyboard.java and use if or switch logic.
private LatinKeyboard getSelectedSubtype() {
final InputMethodSubtype subtype = mInputMethodManager.getCurrentInputMethodSubtype();
String s = subtype.getLocale();
switch (s) {
case "ps_AF":
mActiveKeyboard = mPashtoKeyboard;
mCurKeyboard = mPashtoKeyboard;
break;
case "fa_AF":
mCurKeyboard = mFarsiKeyboard;
break;
default:
mCurKeyboard = mQwertyKeyboard;
}
return mCurKeyboard;
}
And edit methods.xml to add subtypes:
<input-method xmlns:android="http://schemas.android.com/apk/res/android"
android:settingsActivity="com.sunzala.afghankeyboard.android.ImePreferences"
android:supportsSwitchingToNextInputMethod="true">
<subtype
android:imeSubtypeLocale="en_US"
android:imeSubtypeMode="keyboard"
android:label="#string/label_subtype_generic" />
<subtype
android:imeSubtypeLocale="ps_AF"
android:imeSubtypeMode="keyboard"
android:label="#string/label_subtype_generic" />
<subtype
android:imeSubtypeLocale="fa_AF"
android:imeSubtypeMode="keyboard"
android:label="#string/label_subtype_generic" />
</input-method>
For emoticons: Find library and integrate it with a keyboard. The emoticons will display with a key press.
if (primaryCode == -10000) {
showEmoticons();
}
Where -10000 is keycode.