Fragment 类
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
片段是应用程序的用户界面或行为中的一部分,可以放置在其中 Activity。
[Android.Runtime.Register("android/app/Fragment", DoNotGenerateAcw=true)]
public class Fragment : Java.Lang.Object, Android.Content.IComponentCallbacks2, Android.Views.View.IOnCreateContextMenuListener, IDisposable
[<Android.Runtime.Register("android/app/Fragment", DoNotGenerateAcw=true)>]
type Fragment = class
inherit Object
interface IComponentCallbacks2
interface IComponentCallbacks
interface IJavaObject
interface IDisposable
interface IJavaPeerable
interface View.IOnCreateContextMenuListener
- 继承
- 派生
- 特性
- 实现
注解
此类在 API 级别 28 中已弃用。 使用 Jetpack 片段库androidx.fragment.app.Fragment 在所有设备和 访问生命周期时保持一致的行为。
Fragment 是应用程序的用户界面或行为中的一部分,可放置在活动中。 与片段的交互是通过 FragmentManager 完成的,可以通过 Activity.getFragmentManager() 和 Fragment.getFragmentManager()获取。 Fragment 类可用于多种方法来实现各种结果。 在核心中,它表示在较大活动中运行的特定操作或接口。 片段与它所处于的活动密切相关,不能与它位于的活动紧密相连,不能与一个片段分开使用。 虽然 Fragment 定义了其自己的生命周期,但该生命周期依赖于其活动:如果停止活动,则无法启动其内部的片段;销毁活动时,将销毁所有片段。 Fragment 的所有子类都必须包含公共无参数构造函数。 框架通常会在需要时(尤其是在状态还原期间)重新实例化片段类,并且需要能够找到此构造函数来实例化它。 如果 no 参数构造函数不可用,则在某些情况下,状态还原期间将发生运行时异常。
有关使用片段的详细信息,请阅读 片段 开发人员指南。
虽然片段的生命周期与自己的活动有关,但它在标准活动生命周期上有自己的皱痕。 它包括基本的活动生命周期方法,如 onResume(),但重要的是与与活动和 UI 生成交互相关的方法。 调用以使片段恢复到恢复状态(与用户交互)的核心生命周期方法系列是:在片段与其活动关联后调用 onAttach(Activity)。 onCreate(Bundle)调用以执行片段的初始创建。 onCreateView(LayoutInflater, ViewGroup, Bundle) 创建并返回与片段关联的视图层次结构。 onActivityCreated(Bundle) 告诉片段,其活动已完成自己的 Activity.onCreate()。 onViewStateRestored(Bundle)告诉片段,其视图层次结构的所有已保存状态都已还原。 onStart() 使片段对用户可见(基于其正在启动的活动)。 onResume() 使片段开始与用户交互(基于其正在恢复的活动)。 由于不再使用片段,它会经历一系列反向回调:onPause() 片段不再与用户交互,因为其活动正在暂停,或者片段操作正在活动中修改它。 onStop() 片段不再对用户可见,因为其活动正在停止,或者片段操作正在活动中修改它。 onDestroyView() 允许片段清理与其视图关联的资源。 onDestroy() 调用执行片段状态的最终清理。 onDetach() 在片段不再与其活动关联之前立即调用。 布局片段可用作应用程序布局的一部分,使你可以更好地模块化代码,并更轻松地将用户界面调整为正在运行的屏幕。 例如,我们可以查看由项目列表组成的简单程序,并显示每个项的详细信息。
活动的布局 XML 可以包括 <片段> 标记,用于在布局中嵌入片段实例。 例如,下面是嵌入一个片段的简单布局:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent">
<fragment class="com.example.android.apis.app.FragmentLayout$TitlesFragment"
android:id="@+id/titles"
android:layout_width="match_parent" android:layout_height="match_parent" />
</FrameLayout>
布局以正常方式安装在活动中:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fragment_layout);
}
标题片段(显示标题列表)相当简单,它的大部分工作都依赖于 ListFragment。 请注意单击某个项的实现:根据当前活动的布局,它可以创建并显示一个新片段以显示就地的详细信息(稍后更详细),或启动一个新活动以显示详细信息。 此示例改编自 Android 示例。
public static class TitlesFragment extends ListFragment {
boolean mDualPane;
int mCurCheckPosition = 0;
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
// Populate list with our static array of titles.
setListAdapter(new ArrayAdapter<String>(getActivity(),
android.R.layout.simple_list_item_activated_1, Shakespeare.TITLES));
// Check to see if we have a frame in which to embed the details
// fragment directly in the containing UI.
View detailsFrame = getActivity().findViewById(R.id.details);
mDualPane = detailsFrame != null && detailsFrame.getVisibility() == View.VISIBLE;
if (savedInstanceState != null) {
// Restore last state for checked position.
mCurCheckPosition = savedInstanceState.getInt("curChoice", 0);
}
if (mDualPane) {
// In dual-pane mode, the list view highlights the selected item.
getListView().setChoiceMode(ListView.CHOICE_MODE_SINGLE);
// Make sure our UI is in the correct state.
showDetails(mCurCheckPosition);
}
}
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putInt("curChoice", mCurCheckPosition);
}
@Override
public void onListItemClick(ListView l, View v, int position, long id) {
showDetails(position);
}
/**
* Helper function to show the details of a selected item, either by
* displaying a fragment in-place in the current UI, or starting a
* whole new activity in which it is displayed.
*/
void showDetails(int index) {
mCurCheckPosition = index;
if (mDualPane) {
// We can display everything in-place with fragments, so update
// the list to highlight the selected item and show the data.
getListView().setItemChecked(index, true);
// Check what fragment is currently shown, replace if needed.
DetailsFragment details = (DetailsFragment)
getFragmentManager().findFragmentById(R.id.details);
if (details == null || details.getShownIndex() != index) {
// Make new fragment to show this selection.
details = DetailsFragment.newInstance(index);
// Execute a transaction, replacing any existing fragment
// with this one inside the frame.
FragmentTransaction ft = getFragmentManager().beginTransaction();
ft.replace(R.id.details, details);
ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
ft.commit();
}
} else {
// Otherwise we need to launch a new activity to display
// the dialog fragment with selected text.
Intent intent = new Intent();
intent.setClass(getActivity(), DetailsActivity.class);
intent.putExtra("index", index);
startActivity(intent);
}
}
}
显示所选项内容的详细信息片段仅基于内置于应用的字符串数组的索引显示文本字符串:
public static class DetailsFragment extends Fragment {
/**
* Create a new instance of DetailsFragment, initialized to
* show the text at 'index'.
*/
public static DetailsFragment newInstance(int index) {
DetailsFragment f = new DetailsFragment();
// Supply index input as an argument.
Bundle args = new Bundle();
args.putInt("index", index);
f.setArguments(args);
return f;
}
public int getShownIndex() {
return getArguments().getInt("index", 0);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
if (container == null) {
// We have different layouts, and in one of them this
// fragment's containing frame doesn't exist. The fragment
// may still be created from its saved state, but there is
// no reason to try to create its view hierarchy because it
// won't be displayed. Note this is not needed -- we could
// just run the code below, where we would create and return
// the view hierarchy; it would just never be used.
return null;
}
ScrollView scroller = new ScrollView(getActivity());
TextView text = new TextView(getActivity());
int padding = (int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
4, getActivity().getResources().getDisplayMetrics());
text.setPadding(padding, padding, padding, padding);
scroller.addView(text);
text.setText(Shakespeare.DIALOGUE[getShownIndex()]);
return scroller;
}
}
在这种情况下,当用户单击标题时,当前活动中没有详细信息容器,因此游戏片段的单击代码将启动一个新活动以显示详细信息片段:
public static class DetailsActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (getResources().getConfiguration().orientation
== Configuration.ORIENTATION_LANDSCAPE) {
// If the screen is now in landscape mode, we can show the
// dialog in-line with the list so we don't need this activity.
finish();
return;
}
if (savedInstanceState == null) {
// During initial setup, plug in the details fragment.
DetailsFragment details = new DetailsFragment();
details.setArguments(getIntent().getExtras());
getFragmentManager().beginTransaction().add(android.R.id.content, details).commit();
}
}
}
但是,屏幕可能足够大,可以同时显示标题列表和当前所选标题的详细信息。 若要在横向屏幕上使用此类布局,可将此替代布局放置在布局布局下:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent" android:layout_height="match_parent">
<fragment class="com.example.android.apis.app.FragmentLayout$TitlesFragment"
android:id="@+id/titles" android:layout_weight="1"
android:layout_width="0px" android:layout_height="match_parent" />
<FrameLayout android:id="@+id/details" android:layout_weight="1"
android:layout_width="0px" android:layout_height="match_parent"
android:background="?android:attr/detailsElementBackground" />
</LinearLayout>
请注意前面的代码如何调整到此备用 UI 流:游戏片段现在将详细信息片段嵌入到此活动内,如果详细信息活动正在配置中运行,则详细信息活动将自行完成,可在其中显示详细信息的配置中显示详细信息。 当配置更改导致托管这些片段的活动重启时,其新实例可能会使用不同的布局,该布局不包含与以前的布局相同的片段。 在这种情况下,所有以前的片段仍将在新实例中实例化和运行。 但是,不再与 <视图层次结构中的片段> 标记关联的任何内容视图都不会创建其内容视图,并且将从 isInLayout(返回 false)。 (此处的代码还演示如何确定放置在容器中的片段是否不再在该容器的布局中运行,并避免在这种情况下创建其视图层次结构。片段>标记的属性<用于控制在将片段视图附加到父容器时提供的 LayoutParams。 还可以由 onInflate(Activity、AttributeSet、Bundle)中的片段分析它们作为参数。 实例化的片段必须具有某种唯一标识符,以便在需要销毁和重新创建父活动时将其与上一个实例重新关联。 这可以通过以下方式提供:如果未显式提供任何内容,将使用容器的视图 ID。 android:tag 可用于 <片段> ,以提供片段的特定标记名称。 android:id 可用于 <片段> ,以提供片段的特定标识符。 Back Stack:修改片段的事务可以放置在拥有活动的内部后堆栈上。 当用户在活动中按回时,在活动本身完成之前,会弹出后台堆栈上的任何事务。 例如,请考虑使用整数参数实例化的这个简单片段,并在其 UI 中的 TextView 中显示该片段:
public static class CountingFragment extends Fragment {
int mNum;
/**
* Create a new instance of CountingFragment, providing "num"
* as an argument.
*/
static CountingFragment newInstance(int num) {
CountingFragment f = new CountingFragment();
// Supply num input as an argument.
Bundle args = new Bundle();
args.putInt("num", num);
f.setArguments(args);
return f;
}
/**
* When creating, retrieve this instance's number from its arguments.
*/
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mNum = getArguments() != null ? getArguments().getInt("num") : 1;
}
/**
* The Fragment's UI is just a simple text view showing its
* instance number.
*/
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.hello_world, container, false);
View tv = v.findViewById(R.id.text);
((TextView)tv).setText("Fragment #" + mNum);
tv.setBackgroundDrawable(getResources().getDrawable(android.R.drawable.gallery_thumb));
return v;
}
}
一个函数,用于创建片段的新实例,替换显示的任何当前片段实例,并将该更改推送到后台堆栈可以编写为:
void addFragmentToStack() {
mStackLevel++;
// Instantiate a new fragment.
Fragment newFragment = CountingFragment.newInstance(mStackLevel);
// Add the fragment to the activity, pushing this transaction
// on to the back stack.
FragmentTransaction ft = getFragmentManager().beginTransaction();
ft.replace(R.id.simple_fragment, newFragment);
ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
ft.addToBackStack(null);
ft.commit();
}
每次调用此函数后,堆栈上都会有一个新条目,然后按回会弹出它,以将用户返回到活动 UI 处于的任何以前状态。 出现或消失的片段不会为辅助功能生成系统事件,因此使用 View.setAccessibilityPaneTitle(CharSequence)在片段上设置标题,以通知辅助功能用户这些 UI 转换。
Android 参考。android.app.Fragment
本页的某些部分是根据 创建和共享的工作进行的修改,并根据 许可证中所述的条款使用。
构造函数
| 名称 | 说明 |
|---|---|
| Fragment() |
默认构造函数。 |
| Fragment(IntPtr, JniHandleOwnership) |
初始化现有 Java Native Interface 对象的托管表示形式。 |
属性
| 名称 | 说明 |
|---|---|
| Activity |
返回此片段当前关联的活动。 |
| AllowEnterTransitionOverlap |
返回退出转换和输入转换是否重叠。 - 或 - 设置退出转换和输入转换是否重叠。 |
| AllowReturnTransitionOverlap |
返回转换和重新输入转换是否重叠。 - 或 - 设置返回转换和重新输入转换是否重叠。 |
| Arguments |
返回提供给 |
| ChildFragmentManager |
返回一个专用 FragmentManager,用于在此片段中放置和管理片段。 |
| Class |
返回此 |
| Context |
|
| EnterTransition |
返回将视图移动到初始场景的转换。 - 或 - 设置将用于将视图移动到初始场景的转换。 |
| ExitTransition |
返回转换,当片段被删除、隐藏或分离时,将用于将视图移出场景,而不是弹出后堆栈。 - 或 - 设置在删除、隐藏或分离片段时,将用于将视图移出场景的过渡。如果未弹出后台堆栈,则将其隐藏或分离。 |
| FragmentManager |
返回 FragmentManager,以便与与此片段的活动关联的片段进行交互。 |
| Handle |
基础 Android 实例的句柄。 (继承自 Object) |
| Host |
返回此片段的主机对象。 |
| Id |
返回此片段已知的标识符。 |
| IsAdded |
如果片段当前已添加到其活动,则返回 true。 |
| IsDetached |
如果片段已从 UI 显式分离,则返回 true。 |
| IsHidden |
如果片段已被隐藏,则返回 true。 |
| IsInLayout |
如果布局通过片段>标记作为活动视图层次结构的一部分包含,则<返回 true。 |
| IsRemoving |
如果当前正在从其活动中删除此片段,则返回 true。 |
| IsResumed |
如果片段处于恢复状态,则返回 true。 |
| IsStateSaved |
如果添加此片段并且其状态已由其主机保存,则返回 true。 |
| IsVisible |
如果片段当前对用户可见,则返回 true。 |
| JniIdentityHashCode |
获取为此对等方存储的Java标识哈希代码。 (继承自 Object) |
| JniManagedPeerState |
获取运行时上次分配的状态标志。 (继承自 JavaObject) |
| JniPeerMembers |
为 Android.App.Fragment 提供 JNI 绑定基础结构。 |
| LayoutInflater |
返回用于扩充此片段视图的缓存 LayoutInflater。 |
| LoaderManager |
返回此片段的 LoaderManager,根据需要创建它。 |
| ParentFragment |
返回包含此片段的父片段。 |
| PeerReference |
获取此Java对等方的 JNI 对象引用。 (继承自 Object) |
| ReenterTransition |
返回由于弹出后退堆栈而返回时,将用于将视图移动到场景中的转换。 - 或 - 设置在返回时用于在返回时将视图移动到场景中的切换,因为弹出后堆栈。 |
| Resources |
获取与片段的主机关联的资源。 |
| RetainInstance |
控制片段实例是否在活动重新创建(例如从配置更改)中保留。 |
| ReturnTransition |
返回转换,当片段准备删除、隐藏或分离时,将用于将视图移出场景,因为弹出后堆栈。 - 或 - 设置在片段准备删除、隐藏或分离时用于将视图移出场景的过渡,因为弹出后堆栈。 |
| SharedElementEnterTransition |
返回将用于传输到内容场景的共享元素的转换。 - 或 - 设置将用于传输到内容场景的共享元素的转换。 |
| SharedElementReturnTransition |
返回转换,该转换将用于在后台堆栈弹出期间传输回的共享元素。 - 或 - 设置转换,该转换将用于在后台堆栈弹出期间传输回的共享元素。 |
| Tag |
获取片段的标记名称(如果指定)。 |
| TargetFragment |
返回按 |
| TargetRequestCode |
返回由 |
| ThresholdClass |
为 Android.App.Fragment 提供 JNI 绑定基础结构。 |
| ThresholdType |
为 Android.App.Fragment 提供 JNI 绑定基础结构。 |
| UserVisibleHint |
向系统设置一个提示,说明此片段的 UI 当前是否对用户可见。 |
| View |
获取片段布局(返回者 |
方法
| 名称 | 说明 |
|---|---|
| Clone() |
创建并返回此对象的副本。 (继承自 Object) |
| Construct(JniObjectReference, JniObjectReferenceOptions) |
将此对等方的构造委托给运行时的值管理器。 (继承自 JavaObject) |
| Dispose() |
释放此托管对等所持有的 JNI 引用,并从互操作运行时取消注册对等。 (继承自 Object) |
| Dispose(Boolean) |
为子类提供处置挂钩。 此实现不执行任何操作。 (继承自 Object) |
| DisposeUnlessReferenced() |
要求值管理器释放此对等方,除非其映射保留此相同的托管实例。 (继承自 JavaObject) |
| Dump(String, FileDescriptor, PrintWriter, String[]) |
将片段的状态打印到给定流中。 |
| Equals(Object) |
已过时.
子类不能重写 equals()。 |
| Equals(Object) |
测试另一个托管对等方是否引用同一Java对象。 (继承自 JavaObject) |
| GetHashCode() |
已过时.
子类不能重写 hashCode()。 |
| GetString(Int32, Object[]) |
从应用程序包的默认字符串表中返回本地化格式化字符串,替换 Formatter 和 String.format(String, Object) 中定义的格式参数。 |
| GetString(Int32) |
从应用程序包的默认字符串表中返回本地化字符串。 |
| GetText(Int32) |
以托管字符串的形式返回应用程序默认字符串表中的本地化文本。 |
| GetTextFormatted(Int32) |
从应用程序包的默认字符串表中返回本地化样式的 CharSequence。 |
| Instantiate(Context, String, Bundle) |
使用给定的类名创建 Fragment 的新实例。 |
| Instantiate(Context, String) |
与 |
| JavaFinalize() |
已过时.
当垃圾回收确定不再引用该对象时,由对象上的垃圾回收器调用。 (继承自 Object) |
| Notify() |
唤醒正在等待此对象的监视器的单个线程。 (继承自 Object) |
| NotifyAll() |
唤醒正在等待此对象的监视器的所有线程。 (继承自 Object) |
| OnActivityCreated(Bundle) |
创建片段的活动并实例化此片段的视图层次结构时调用。 |
| OnActivityResult(Int32, Result, Intent) |
从上一次调用 |
| OnAttach(Activity) |
已过时.
此方法在 API 级别 23 中已弃用。 |
| OnAttach(Context) |
当片段首次附加到其上下文时调用。 |
| OnAttachFragment(Fragment) |
当片段作为此片段的子级附加时调用。 |
| OnConfigurationChanged(Configuration) |
当设备配置在组件运行时发生更改时由系统调用。 |
| OnContextItemSelected(IMenuItem) |
每当选择上下文菜单中的项时,将调用此挂钩。 |
| OnCreate(Bundle) |
调用以执行片段的初始创建。 |
| OnCreateAnimator(FragmentTransit, Boolean, Int32) |
当片段加载动画时调用。 |
| OnCreateContextMenu(IContextMenu, View, IContextMenuContextMenuInfo) |
当视图的上下文菜单即将显示时调用。 |
| OnCreateOptionsMenu(IMenu, MenuInflater) |
初始化活动标准选项菜单的内容。 |
| OnCreateView(LayoutInflater, ViewGroup, Bundle) |
调用以让片段实例化其用户界面视图。 |
| OnDestroy() |
当片段不再使用时调用。 |
| OnDestroyOptionsMenu() |
当此片段的选项菜单项不再包含在整体选项菜单中时调用。 |
| OnDestroyView() |
从片段分离之前创建的 |
| OnDetach() |
当片段不再附加到其活动时调用。 |
| OnGetLayoutInflater(Bundle) |
返回用于放大此片段视图的 LayoutInflater。 |
| OnHiddenChanged(Boolean) |
当隐藏状态(由片段返回 |
| OnInflate(Activity, IAttributeSet, Bundle) |
已过时.
此方法在 API 级别 23 中已弃用。 |
| OnInflate(Context, IAttributeSet, Bundle) |
在作为视图布局膨胀的一部分创建片段时调用,通常从设置活动的内容视图。 |
| OnInflate(IAttributeSet, Bundle) |
已过时.
此方法在 API 级别 15 中已弃用。 |
| OnLowMemory() |
当整个系统内存不足时,会调用此方法,并且主动运行的进程应剪裁其内存使用率。 |
| OnMultiWindowModeChanged(Boolean, Configuration) |
当片段的活动从全屏模式更改为多窗口模式,反之亦然时调用。 |
| OnMultiWindowModeChanged(Boolean) |
当片段的活动从全屏模式更改为多窗口模式,反之亦然时调用。 |
| OnOptionsItemSelected(IMenuItem) |
每当选择选项菜单中的某个项时,将调用此挂钩。 |
| OnOptionsMenuClosed(IMenu) |
每当选项菜单处于关闭状态(用户取消带有后退/菜单按钮的菜单,或选中某个项时),将调用此挂钩。 |
| OnPause() |
不再恢复片段时调用。 |
| OnPictureInPictureModeChanged(Boolean, Configuration) |
当活动更改到图片中和从图片中模式更改时由系统调用。 |
| OnPictureInPictureModeChanged(Boolean) |
当活动更改到图片中和从图片中模式更改时由系统调用。 |
| OnPrepareOptionsMenu(IMenu) |
准备要显示的屏幕标准选项菜单。 |
| OnRequestPermissionsResult(Int32, String[], Permission[]) |
请求权限的结果的回调。 |
| OnResume() |
当片段对用户可见并主动运行时调用。 |
| OnSaveInstanceState(Bundle) |
调用以要求片段保存其当前动态状态,以便稍后可以在进程的新实例中重新构造它。 |
| OnStart() |
当用户看到片段时调用。 |
| OnStop() |
不再启动片段时调用。 |
| OnTrimMemory(TrimMemory) |
当操作系统确定进程从其进程中剪裁不需要的内存是一个好时机时调用。 |
| OnViewCreated(View, Bundle) |
在返回后 |
| OnViewStateRestored(Bundle) |
当所有已保存状态都还原到片段的视图层次结构时调用。 |
| PostponeEnterTransition() |
推迟进入片段转换,直到 |
| RegisterForContextMenu(View) |
注册要为给定视图显示的上下文菜单(多个视图可以显示上下文菜单)。 |
| RequestPermissions(String[], Int32) |
请求授予此应用程序的权限。 |
| SetEnterSharedElementCallback(SharedElementCallback) |
当自定义转换与片段一起使用时,当未弹出后堆栈时,将调用此片段的输入转换回调。 |
| SetExitSharedElementCallback(SharedElementCallback) |
当自定义转换与片段一起使用时,当此片段附加或分离时,当弹出后堆栈时,将调用退出转换回调。 |
| SetHandle(IntPtr, JniHandleOwnership) |
设置 Handle 属性。 (继承自 Object) |
| SetHasOptionsMenu(Boolean) |
报告此片段希望通过接收调用 |
| SetInitialSavedState(Fragment+SavedState) |
根据 FragmentManager.saveFragmentInstanceState 返回的片段,设置此片段应从第一次构造时还原自身的初始保存状态。 |
| SetMenuVisibility(Boolean) |
设置此片段的菜单是否应可见的提示。 |
| SetPeerReference(JniObjectReference, JniObjectReferenceOptions) |
在不创建 JNI 引用副本的情况下,将引用值存储在控制块中。 (继承自 JavaObject) |
| SetTargetFragment(Fragment, Int32) |
此片段的可选目标。 |
| ShouldShowRequestPermissionRationale(String) |
获取在请求权限之前是否应以理由显示 UI。 |
| StartActivity(Intent, Bundle) |
从片段的包含活动调用 |
| StartActivity(Intent) |
从片段的包含活动调用 |
| StartActivityForResult(Intent, Int32, Bundle) |
从片段的包含活动调用 |
| StartActivityForResult(Intent, Int32) |
从片段的包含活动调用 |
| StartIntentSenderForResult(IntentSender, Int32, Intent, ActivityFlags, ActivityFlags, Int32, Bundle) |
从片段的包含活动调用 |
| StartPostponedEnterTransition() |
调用后 |
| ToArray<T>() |
从此Java数组包装器创建托管数组。 (继承自 Object) |
| ToString() |
返回对象的字符串表示形式。 (继承自 Object) |
| UnregisterForContextMenu(View) |
防止为给定视图显示上下文菜单。 |
| UnregisterFromRuntime() |
从互操作运行时取消注册此Java对等。 (继承自 Object) |
| Wait() |
导致当前线程等待,直到它被唤醒,通常是通过 通知 或 中断。 (继承自 Object) |
| Wait(Int64, Int32) |
使当前线程等待直到唤醒,通常是通过 通知 或 中断,或直到经过一定数量的实时。 (继承自 Object) |
| Wait(Int64) |
使当前线程等待直到唤醒,通常是通过 通知 或 中断,或直到经过一定数量的实时。 (继承自 Object) |
显式接口实现
| 名称 | 说明 |
|---|---|
| IJavaPeerable.Disposed() |
将此对等方标记为已释放,并将 |
| IJavaPeerable.Finalized() |
将此对等方标记为已释放,并将 |
| IJavaPeerable.JniObjectReferenceControlBlock |
获取此对等方使用的本机控制块指针。 (继承自 JavaObject) |
| IJavaPeerable.SetJniIdentityHashCode(Int32) |
存储运行时提供的标识哈希代码。 (继承自 JavaObject) |
| IJavaPeerable.SetJniManagedPeerState(JniManagedPeerStates) |
替换存储的托管对等状态标志。 (继承自 JavaObject) |
| IJavaPeerable.SetPeerReference(JniObjectReference) |
更新对等引用,并在引用无效时释放已释放的对等方控制块。 (继承自 JavaObject) |
| IJavaPeerable.UnregisterFromRuntime() |
从运行时的Java对象查找中删除此实例。 |
扩展方法
| 名称 | 说明 |
|---|---|
| GetJniTypeName(IJavaPeerable) |
获取实例 |
| JavaAs<TResult>(IJavaPeerable) |
尝试强制 |
| JavaCast<TResult>(IJavaObject) |
执行 Android 运行时检查的类型转换。 |
| JavaCast<TResult>(IJavaObject) |
重复使用兼容的托管对等,或获取请求类型的包装器。 |
| TryJavaCast<TResult>(IJavaPeerable, TResult) |
尝试强制 |