blob: 66e16207a3b95e1d81418e0b3157ba2047fd3a20 [file] [log] [blame]
<html devsite="true">
<head>
<title>FragmentFactory</title>
{% setvar book_path %}/reference/kotlin/androidx/_book.yaml{% endsetvar %}
{% include "_shared/_reference-head-tags.html" %}
</head>
<body>
<h1>FragmentFactory</h1>
{% setvar page_path %}androidx/fragment/app/FragmentFactory.html{% endsetvar %}
{% setvar can_switch %}1{% endsetvar %}
{% include "reference/_kotlin_switcher2.md" %}
<p>
<pre>class FragmentFactory</pre>
</p>
<hr>
<p>Interface used to control the instantiation of <code><a href="/reference/kotlin/androidx/fragment/app/Fragment.html">Fragment</a></code> instances. Implementations can be registered with a <code><a href="/reference/kotlin/androidx/fragment/app/FragmentManager.html">FragmentManager</a></code> via <code><a href="/reference/kotlin/androidx/fragment/app/FragmentManager.html#setFragmentFactory(androidx.fragment.app.FragmentFactory)">FragmentManager#setFragmentFactory(FragmentFactory)</a></code>.</p>
<div class="devsite-table-wrapper">
<table class="responsive">
<thead>
<tr>
<th colspan="2">See also</th>
</tr>
</thead>
<tbody>
<tr>
<td><code><a href="/reference/kotlin/androidx/fragment/app/FragmentManager.html#setFragmentFactory(androidx.fragment.app.FragmentFactory)">setFragmentFactory</a></code></td>
<td width="100%">
<p>androidx.fragment.app.FragmentManager#setFragmentFactory(FragmentFactory)</p>
</td>
</tr>
</tbody>
</table>
</div>
<h2>Summary</h2>
<div class="devsite-table-wrapper">
<table class="responsive">
<thead>
<tr>
<th colspan="2"><h3>Public constructors</h3></th>
</tr>
</thead>
<tbody>
<tr>
<td>
<div><code><a href="/reference/kotlin/androidx/fragment/app/FragmentFactory.html#FragmentFactory()">FragmentFactory</a>()</code></div>
</td>
</tr>
</tbody>
</table>
</div>
<div class="devsite-table-wrapper">
<table class="responsive">
<thead>
<tr>
<th colspan="2"><h3>Public functions</h3></th>
</tr>
</thead>
<tbody>
<tr>
<td><code><a href="/reference/kotlin/androidx/fragment/app/Fragment.html">Fragment</a></code></td>
<td width="100%">
<div><code><a href="/reference/kotlin/androidx/fragment/app/FragmentFactory.html#instantiate(java.lang.ClassLoader,java.lang.String)">instantiate</a>(classLoader:&nbsp;<a href="https://developer.android.com/reference/java/lang/ClassLoader.html">ClassLoader</a>,&nbsp;className:&nbsp;<a href="https://developer.android.com/reference/java/lang/String.html">String</a>)</code></div>
<p>Create a new instance of a Fragment with the given class name.</p>
</td>
</tr>
<tr>
<td><code><a href="https://developer.android.com/reference/java/lang/Class.html">Class</a>&lt;<a href="/reference/kotlin/androidx/fragment/app/Fragment.html">Fragment</a>&gt;</code></td>
<td width="100%">
<div><code><a href="/reference/kotlin/androidx/fragment/app/FragmentFactory.html#loadFragmentClass(java.lang.ClassLoader,java.lang.String)">loadFragmentClass</a>(classLoader:&nbsp;<a href="https://developer.android.com/reference/java/lang/ClassLoader.html">ClassLoader</a>,&nbsp;className:&nbsp;<a href="https://developer.android.com/reference/java/lang/String.html">String</a>)</code></div>
<p>Parse a Fragment Class from the given class name.</p>
</td>
</tr>
</tbody>
</table>
</div>
<h2>Public constructors</h2>
<div><a name="FragmentFactory--"></a>
<h3 class="api-name" id="FragmentFactory()">FragmentFactory</h3>
<pre class="api-signature no-pretty-print"><a href="/reference/kotlin/androidx/fragment/app/FragmentFactory.html#FragmentFactory()">FragmentFactory</a>()</pre>
</div>
<h2>Public functions</h2>
<div><a name="instantiate(java.lang.ClassLoader, java.lang.String)"></a><a name="instantiate-java.lang.ClassLoader-java.lang.String-"></a>
<h3 class="api-name" id="instantiate(java.lang.ClassLoader,java.lang.String)">instantiate</h3>
<pre class="api-signature no-pretty-print">fun&nbsp;<a href="/reference/kotlin/androidx/fragment/app/FragmentFactory.html#instantiate(java.lang.ClassLoader,java.lang.String)">instantiate</a>(classLoader:&nbsp;<a href="https://developer.android.com/reference/java/lang/ClassLoader.html">ClassLoader</a>,&nbsp;className:&nbsp;<a href="https://developer.android.com/reference/java/lang/String.html">String</a>):&nbsp;<a href="/reference/kotlin/androidx/fragment/app/Fragment.html">Fragment</a></pre>
<p>Create a new instance of a Fragment with the given class name. This uses <code><a href="/reference/kotlin/androidx/fragment/app/FragmentFactory.html#loadFragmentClass(java.lang.ClassLoader,java.lang.String)">loadFragmentClass</a></code> and the empty constructor of the resulting Class by default.</p>
<div class="devsite-table-wrapper">
<table class="responsive">
<thead>
<tr>
<th colspan="2">Returns</th>
</tr>
</thead>
<tbody>
<tr>
<td><code><a href="/reference/kotlin/androidx/fragment/app/Fragment.html">Fragment</a></code></td>
<td width="100%">
<p>Returns a new fragment instance.</p>
</td>
</tr>
</tbody>
</table>
</div>
<div class="devsite-table-wrapper">
<table class="responsive">
<thead>
<tr>
<th colspan="2">Parameters</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>classLoader:&nbsp;<a href="https://developer.android.com/reference/java/lang/ClassLoader.html">ClassLoader</a></code></td>
<td width="100%">
<p>The default classloader to use for instantiation</p>
</td>
</tr>
<tr>
<td><code>className:&nbsp;<a href="https://developer.android.com/reference/java/lang/String.html">String</a></code></td>
<td width="100%">
<p>The class name of the fragment to instantiate.</p>
</td>
</tr>
</tbody>
</table>
</div>
<div class="devsite-table-wrapper">
<table class="responsive">
<thead>
<tr>
<th colspan="2">Throws</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>androidx.fragment.app.Fragment.InstantiationException</code></td>
<td width="100%">
<p>If there is a failure in instantiating the given fragment class. This is a runtime exception; it is not normally expected to happen.</p>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<div><a name="loadFragmentClass(java.lang.ClassLoader, java.lang.String)"></a><a name="loadFragmentClass-java.lang.ClassLoader-java.lang.String-"></a>
<h3 class="api-name" id="loadFragmentClass(java.lang.ClassLoader,java.lang.String)">loadFragmentClass</h3>
<pre class="api-signature no-pretty-print">fun&nbsp;<a href="/reference/kotlin/androidx/fragment/app/FragmentFactory.html#loadFragmentClass(java.lang.ClassLoader,java.lang.String)">loadFragmentClass</a>(classLoader:&nbsp;<a href="https://developer.android.com/reference/java/lang/ClassLoader.html">ClassLoader</a>,&nbsp;className:&nbsp;<a href="https://developer.android.com/reference/java/lang/String.html">String</a>):&nbsp;<a href="https://developer.android.com/reference/java/lang/Class.html">Class</a>&lt;<a href="/reference/kotlin/androidx/fragment/app/Fragment.html">Fragment</a>&gt;</pre>
<p>Parse a Fragment Class from the given class name. The resulting Class is kept in a global cache, bypassing the <code><a href="https://developer.android.com/reference/java/lang/Class.html#forName(java.lang.String)">Class#forName(String)</a></code> calls when passed the same class name again.</p>
<div class="devsite-table-wrapper">
<table class="responsive">
<thead>
<tr>
<th colspan="2">Returns</th>
</tr>
</thead>
<tbody>
<tr>
<td><code><a href="https://developer.android.com/reference/java/lang/Class.html">Class</a>&lt;<a href="/reference/kotlin/androidx/fragment/app/Fragment.html">Fragment</a>&gt;</code></td>
<td width="100%">
<p>Returns the parsed Fragment Class</p>
</td>
</tr>
</tbody>
</table>
</div>
<div class="devsite-table-wrapper">
<table class="responsive">
<thead>
<tr>
<th colspan="2">Parameters</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>classLoader:&nbsp;<a href="https://developer.android.com/reference/java/lang/ClassLoader.html">ClassLoader</a></code></td>
<td width="100%">
<p>The default classloader to use for loading the Class</p>
</td>
</tr>
<tr>
<td><code>className:&nbsp;<a href="https://developer.android.com/reference/java/lang/String.html">String</a></code></td>
<td width="100%">
<p>The class name of the fragment to parse.</p>
</td>
</tr>
</tbody>
</table>
</div>
<div class="devsite-table-wrapper">
<table class="responsive">
<thead>
<tr>
<th colspan="2">Throws</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>androidx.fragment.app.Fragment.InstantiationException</code></td>
<td width="100%">
<p>If there is a failure in parsing the given fragment class. This is a runtime exception; it is not normally expected to happen.</p>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</body>
</html>