Research on loading Optimization of web games embedded in WEBVIEW, webview

Source: Internet
Author: User

Research on loading Optimization of web games embedded in WEBVIEW, webview
--------------------------------------------------- The story begins -----------------------------------------------------------------------------------------

At the front-end time, the internship company will create a WEB_app on the Android platform. I will not elaborate on what it is.

In an APP, almost all pages are webpages with a WEBVIEW structure.

One of the pictures is relatively complex, and there are a lot of animations and interactions. It was originally intended to use native android to develop this page. However, as a non-paid intern, I was not satisfied! Do you dare to believe it?

I think it should also be done using WEB. It will be available for other platforms in the future. Later I took some time to make a simple demo, which was implemented using the game engine,

Everybody knows recently the egret game engine is very hot, so at last I was implementing this DEMO with COCOS2D-JS... don't ask me why.

After the DEMO is completed, all the bosses of the company are very good! Good! Smooth! Pretty! Cross-platform!

But the loading time is too long. What if someone else uses a 2G network? Cannot be opened for half a day! After discussion, we finally decided to use native android !!! Do you dare to believe it? Let me use native android to do this ....

As a non-paid intern, I am not satisfied !! I said this can be optimized. Please give me some time to look for it. The big boys said: It's too late. Please use your native android !!

As a non-paid intern, I gave in ....

But I still took the time to find out if I could put the file of a huge engine directly on ANDROID, which is actually not big...

There are not many materials on the Internet, so I finally got it out and shared it with you.

------------------------------------------- End of the story -------------------------------------------------------------------------------------------


The main idea is to use ContentProvider to share the file in the mobile phone so that the webpage can access the content in the androidSD card.

First, put all the js css images and audios used for the webpage under the SD of the mobile phone (put the code in the program instead of grabbing the user's mobile phone !)

Directory: SD card:/html/a.png

import java.io.File;import java.io.FileNotFoundException;import android.content.ContentProvider;import android.content.ContentValues;import android.content.res.AssetFileDescriptor;import android.content.res.AssetManager;import android.database.Cursor;import android.net.Uri;import android.os.ParcelFileDescriptor;import android.util.Log;public class cctt extends ContentProvider {private  static final String URI_PREFIX = "content://darkzone.game.zed.yang";@Override      public ParcelFileDescriptor openFile(Uri uri, String mode) throws FileNotFoundException {          Log.e("path1:", uri.getPath());          File file = new File(uri.getPath());          ParcelFileDescriptor parcel = ParcelFileDescriptor.open(file, ParcelFileDescriptor.MODE_READ_ONLY);          return parcel;                }    @Override      public AssetFileDescriptor openAssetFile (Uri uri, String mode) throws FileNotFoundException{          AssetManager am = getContext().getAssets();            String path = uri.getPath().substring(1);            Log.e("path:", path);                             String tpath = "/sdcard/html/"+path;          File file = new File(tpath);          if (file.exists()) {              Log.e("path2:", tpath);              Uri turi = Uri.parse(URI_PREFIX+tpath);              return super.openAssetFile(turi, mode);          }                            return super.openAssetFile(uri, mode);      }  @Overridepublic boolean onCreate() {// TODO Auto-generated method stubreturn false;}@Overridepublic Cursor query(Uri uri, String[] projection, String selection,String[] selectionArgs, String sortOrder) {// TODO Auto-generated method stubreturn null;}@Overridepublic String getType(Uri uri) {// TODO Auto-generated method stubreturn null;}@Overridepublic Uri insert(Uri uri, ContentValues values) {// TODO Auto-generated method stubreturn null;}@Overridepublic int delete(Uri uri, String selection, String[] selectionArgs) {// TODO Auto-generated method stubreturn 0;}@Overridepublic int update(Uri uri, ContentValues values, String selection,String[] selectionArgs) {// TODO Auto-generated method stubreturn 0;}}

Write in the webpage as follows:


In AndroidManifest. xml, you also need to add

<Provider android: name = "cctt" android: authorities = "darkzone. game. zed. yang"> </provider>


In this way, resources in the SD card will be used on the webpage.


Welcome to leave a message... although no one left a message ......


Welcome to my own nest, DarkZone. Although it has not been completed, the development has also stagnated. Recently, it has not been available, and people are also impetuous. Let alone start again.

Click to enter the DarkZone dark domain game

Reprinted please indicate the source Thank you: http://blog.csdn.net/ycd_harry/article/details/42237797


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.