Android でのバックグラウンド スレッド
重要
このオファリングは現在アルファ版であり、変更される可能性があります。
バックグラウンド スレッド機能を使用すると、Mobile SDK では、バナー、スポット、ネイティブ、ビデオなどのさまざまな AdUnit に対する広告要求を、UI スレッドではなくバックグラウンド スレッドとして実行できます。 この機能は、メソッド (enableBackgroundThreading
) によってオンまたはオフにすることができます。 既定では、この機能は Mobile SDK では無効になっています。
メソッド
この機能では、次のメソッドがサポートされています。
enableBackgroundThreading(boolean)
このメソッドを使用すると、バックグラウンド スレッドで実行される AdRequests に基づいて、バックグラウンド スレッド機能フラグを有効または無効にすることができます。 既定では、 メソッドのブール値は false に設定されます (Android の AsyncTask を使用します)。 バックグラウンド スレッドの機能を有効にするには、値を true に設定します。
/**
* This API can be used to process Ad request on the BGThread,
* @param enable
* true - For processing the AdRequest on BGThread
* false - For processing the AdRequest using AsyncTask
* default is set to false.
* */
public static void enableBackgroundThreading(boolean enable)
Init()
アプリのライフサイクルの早い段階で Mobile SDK を初期化し、AdRequest の間に UI スレッドを必要とするタスクを事前に実行するメソッド。 このメソッドにより、Mobile SDK では、実際の AdRequest の実行中にのみバックグラウンド スレッドが使用されます。 init メソッドの完了について知るために、 メソッドと共にリスナーを渡すことができます。
/**
* Should be called at the early lifecycle of the app.
* You can pass in a listener to listen to the completion of the init method.
* If you don't integrate with this API, you might fail to get the aaid, user agents for initial ad requests.
* This needs to be called on UI thread.
*/
public static void init(final Context context, final InitListener listener)
例
// enable the Background threading
SDKSettings.enableBackgroundThreading(true);
// call init before requesting the Ad
SDKSettings.init(context, new SDKSettings.InitListener()
{
@Override public void onInitFinished()
{
// Init has finished.
}
}
);