后退按钮显示接触后不工作 [英] Back button not working after displaying Contact
问题描述
我打从专业的Android 4的可点击列表项code中的code基本上是:
公共类MainActivity扩展ListActivity实现OnItemClickListener
{
@覆盖
公共无效的onCreate(包savedInstanceState)
{
super.onCreate(savedInstanceState);
CursorLoader装载机=新CursorLoader(这一点,Contacts.CONTENT_URI,空,
NULL,NULL,Contacts.DISPLAY_NAME +ASC);
光标光标= loader.loadInBackground();
的String []列=新的String [] {Contacts.DISPLAY_NAME};
INT []意见=新INT [] {android.R.id.text1};
SimpleCursorAdapter适配器=新SimpleCursorAdapter(这一点,
android.R.layout.simple_list_item_1,光标,列,视图,
CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER);
setListAdapter(适配器);
getListView()setOnItemClickListener(本)。
}
@覆盖
公共无效onItemClick(适配器视图<>适配器视图,视图中查看,INT位置,长ID)
{
乌里contactUri = ContentUris.withAppendedId(Contacts.CONTENT_URI,ID);
意向意图=新的意图(Intent.ACTION_VIEW,contactUri);
startActivity(意向);
}
}
这一切工作正常。我看到联系人列表,当我点击一个名字它打开地址簿的那个人。
的问题是,后退按钮不从地址簿工作。根据这本书,攻牙从地址簿中的后退按钮应该把我带回上述活动。但是相反,我带回到主屏幕。
我的应用程序仍在运行,当我切换到手动我回到它和列表视图是在适当的previous滚动位置,等等。
这是在Android 4.1.1。我不知道是否有额外的东西我应该实现,使这项工作?
这是清单文件:
<舱单的xmlns:机器人=http://schemas.android.com/apk/res/android
包=com.example.contactslist
安卓版code =1
机器人:VERSIONNAME =1.0>
<用途-SDK
安卓的minSdkVersion =16
机器人:targetSdkVersion =15/>
<使用-权限的Android:名称=android.permission.READ_CONTACTS/>
<应用
机器人:图标=@可绘制/ ic_launcher
机器人:标签=@字符串/ APP_NAME
机器人:主题=@风格/ AppTheme>
<活动
机器人:名称=。MainActivity
机器人:标签=@字符串/ title_activity_main>
<意向滤光器>
<作用机器人:名称=android.intent.action.MAIN/>
<类机器人:名称=android.intent.category.LAUNCHER/>
&所述; /意图滤光器>
< /活性GT;
< /用途>
< /舱单>
听起来像是你的Activity栈是越来越搞砸了不知。 尝试添加下面你开始你的电话给startActivity(意向)
在 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
I am playing with the "Clickable List Items" code from Pro Android 4. The code is basically:
public class MainActivity extends ListActivity implements OnItemClickListener
{
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
CursorLoader loader = new CursorLoader(this, Contacts.CONTENT_URI, null,
null, null, Contacts.DISPLAY_NAME + " ASC");
Cursor cursor = loader.loadInBackground();
String[] columns = new String[] { Contacts.DISPLAY_NAME };
int[] views = new int[] { android.R.id.text1 };
SimpleCursorAdapter adapter = new SimpleCursorAdapter(this,
android.R.layout.simple_list_item_1, cursor, columns, views,
CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER);
setListAdapter(adapter);
getListView().setOnItemClickListener(this);
}
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int position, long id)
{
Uri contactUri = ContentUris.withAppendedId(Contacts.CONTENT_URI, id);
Intent intent = new Intent(Intent.ACTION_VIEW, contactUri);
startActivity(intent);
}
}
This all works fine. I see the list of contacts and when I tap a name it opens the address book for that person.
The problem is that the Back button does not work from the address book. According to the book , tapping the back button from the address book should bring me back to the above Activity. But instead I am taken back to the home screen.
My app is still running, when I switch to it manually I get back to it and the list view is at the proper previous scroll position, etc.
This is on Android 4.1.1. I'm wondering if there is something extra I should implement to make this work?
This is the Manifest file:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.contactslist"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="16"
android:targetSdkVersion="15" />
<uses-permission android:name="android.permission.READ_CONTACTS"/>
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Sounds like your Activity stack is getting messed up somehow. Try adding the following before you start your call to startActivity(intent)
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
这篇关于后退按钮显示接触后不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!