Java Question Activity From eclipse

giuseppe909090

Member
Licensed User
Longtime User
Hi,
I have to develop a library for sygic fleet, I can see a activity from eclipse in basic4android?
Thank you in advance.
 

giuseppe909090

Member
Licensed User
Longtime User
eclipse xml

Hi martin

thanks for the answer how do I export an xml It contains the EditText and the button?
Giuseppe.
 

giuseppe909090

Member
Licensed User
Longtime User
here is the logs:



** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
** Service (alw) Create **
** Service (alw) Start **
java.lang.VerifyError: com/sygic/demo/SdkDemoActivity
at java.lang.Class.newInstanceImpl(Native Method)
at java.lang.Class.newInstance(Class.java:1319)
at android.app.Instrumentation.newActivity(Instrumentation.java:1027)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1885)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1995)
at android.app.ActivityThread.access$600(ActivityThread.java:128)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1161)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4514)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557)
at dalvik.system.NativeStart.main(Native Method)

:sign0085:
 

warwound

Expert
Licensed User
Longtime User
Hi martin

thanks for the answer how do I export an xml It contains the EditText and the button?
Giuseppe.

Any Resources used by your library must be added to one the B4A project's \Objects\res folders.

Layout XML files must be put in \Objects\res\layout for example.

All resources manually added to a B4A project's res folder must be set to read-only, otherwise the B4A compiler will delete them when you compile your project.

Now you need a way to access those Resources from your library code - your existing code probably uses something such as R.layout.my_layout_filename.

You might find this thread interesting: http://www.b4x.com/forum/basic4android-updates-questions/20377-need-some-help.html#post117352

Let's say you have a layout file main_menu.xml in \Objects\res\layout and that file is set to read-only.

In your existing Android based java you might use:

B4X:
setContentView(R.layout.main_menu);

In your B4A library java you could use:

B4X:
LayoutInflater myLayoutInflater=LayoutInflater.from(yourActivityContext);
int layoutId=BA.applicationContext.getResources().getIdentifier("main_menu", "layout", BA.packageName);
setContentView(myLayoutInflater.inflate(layoutId, null));

You'd need to modify that - set the value of yourActivityContext to the Activity Context.

Martin.
 

giuseppe909090

Member
Licensed User
Longtime User
Martin and this is my class:


HTML:
package com.sygic.demo;





import android.app.Activity;
import android.content.Intent;
import android.view.LayoutInflater;
import anywheresoftware.b4a.BA;
import anywheresoftware.b4a.BA.ActivityObject;
import anywheresoftware.b4a.BA.ShortName;
import anywheresoftware.b4a.BA.Version;
@ActivityObject
@ShortName("sdksygic")
@Version(1)
public class sygic extends Activity{
   
      
      public Intent CreateIntent(BA pBA){
         LayoutInflater myLayoutInflater=LayoutInflater.from(pBA.context);
          int layoutId=BA.applicationContext.getResources().getIdentifier("main", "layout", BA.packageName);
            setContentView(myLayoutInflater.inflate(layoutId, null));
          int surfaceid=BA.applicationContext.getResources().getIdentifier("main_surface", "id", BA.packageName);
        setContentView(myLayoutInflater.inflate(surfaceid, null));
        int main_addressid=BA.applicationContext.getResources().getIdentifier("main_address", "id", BA.packageName);
        setContentView(myLayoutInflater.inflate(main_addressid, null));
        int TableRow01id=BA.applicationContext.getResources().getIdentifier("TableRow01", "id", BA.packageName);
        setContentView(myLayoutInflater.inflate(TableRow01id, null));
        int main_btn_locationid=BA.applicationContext.getResources().getIdentifier("main_btn_location", "id", BA.packageName);
        setContentView(myLayoutInflater.inflate(main_btn_locationid, null));
        int main_btn_navigateid=BA.applicationContext.getResources().getIdentifier("main_btn_navigate", "id", BA.packageName);
        setContentView(myLayoutInflater.inflate(main_btn_navigateid, null));
        int main_btn_stopid=BA.applicationContext.getResources().getIdentifier("main_btn_stop", "id", BA.packageName);
        setContentView(myLayoutInflater.inflate(main_btn_stopid, null));
        int main_btn_stop_serviceid=BA.applicationContext.getResources().getIdentifier("main_btn_stop_service", "id", BA.packageName);
        setContentView(myLayoutInflater.inflate(main_btn_stop_serviceid, null));
        int main_btn_showid=BA.applicationContext.getResources().getIdentifier("main_btn_show", "id", BA.packageName);
        setContentView(myLayoutInflater.inflate(main_btn_showid, null));
        int TableRow02id=BA.applicationContext.getResources().getIdentifier("TableRow02", "id", BA.packageName);
        setContentView(myLayoutInflater.inflate(TableRow02id, null));
        int main_btn_initid=BA.applicationContext.getResources().getIdentifier("main_btn_init", "id", BA.packageName);
        setContentView(myLayoutInflater.inflate(main_btn_initid, null));
        int main_btn_exitid=BA.applicationContext.getResources().getIdentifier("main_btn_exit", "id", BA.packageName);
        setContentView(myLayoutInflater.inflate(main_btn_exitid, null));
        int main_btn_exit_appid=BA.applicationContext.getResources().getIdentifier("main_btn_exit_app", "id", BA.packageName);
        setContentView(myLayoutInflater.inflate(main_btn_exit_appid, null));
        int main_btn_testid=BA.applicationContext.getResources().getIdentifier("main_btn_test", "id", BA.packageName);
        setContentView(myLayoutInflater.inflate(main_btn_testid, null));
        int main_btn_hideid=BA.applicationContext.getResources().getIdentifier("main_btn_hide", "id", BA.packageName);
        setContentView(myLayoutInflater.inflate(main_btn_hideid, null));
        int main_textid=BA.applicationContext.getResources().getIdentifier("main_text", "id", BA.packageName);
        setContentView(myLayoutInflater.inflate(main_textid, null));
      
        return  new Intent(pBA.activity,SdkDemoActivity.class);
        
        
       }
      
   
      
      
}

All items are in my main.xml
 

warwound

Expert
Licensed User
Longtime User
Hi again.

I think i made it sound more simple than it is to access Resources from a B4A library...

It's not rocket science but, you ought to find all places in your library code where the R class is used to identify a Resource.

Examples are:

B4X:
R.drawable.my_drawable_name
R.layout.my_layout_name
R.id.id_of_ a_view

Some uses of the R class return an integer id, some return a reference to a layout and some return a Drawable.

Each different type of reference to the R class needs a slightly different bit of code to convert from native Android java R class to the R class that is compiled with a B4A project.

I see you posted some links to your source code, it's a sunny Saturday afternoon here in Norfolk, UK and i shan't take the time right now to look at your Android java source to see exactly what your need to change.

If you want to look yourself for all places in the Android java where the R class is accessed and post those bits of code i'll give you some methods to enable you to use the same Resources in B4A.

Otherwise you'll have to wait til nightfall or tomorrow morning and i'll look through your code and find those references to the R class myself..

Meanwhile it's fine n sunny and just too nice to sit in front of a computer: Kings Lynn (PE30) weather | PE30, Kings Lynn, Norfolk latest hourly weather | WorldWeatherOnline.com :sign0008:

Martin.
 

warwound

Expert
Licensed User
Longtime User
I've got your code downloaded now and am looking at the library source.

First thing to note is that you must create the Activity which you want to add to your B4A project as a standard java project and NOT as an Android project.

Create it as a standard java project then export it as a .jar file with the corresponding .xml file.

Next i see your project uses a load of .so files, these are NDK files i think?, but anyway they will not be automatically loaded in a B4A library, see Erel's post here.

Trying to run the Android project on my ZTE Blade (CyanogenMod7 Gingerbread) does very little, i click the 'Sdk demo' button and try various things on the next Activity but just get a toast message 'Api is closed'.
It does the same on my Huawei Ascend G300.

Both devices are on the list of supported devices.

So it's not looking like an easy library to create - you have a lot of technical things to sort out before you can even try a test B4A library project.

Is this your first B4A library?
If it is i'd suggest starting with something far less complicated - don't want to sound patronising there but this really is quite an ambitous first project!

Take a look at the attached Eclipse java project - it should help you if you decide to continue...

The Helper class is the only library class that would be visible to B4A, the @Hide annotation will hide the other two Activities.

Search the forum for DependsOn and you'll see how that annotation should be used in the library to reference external .jar files.

The Helper class also contains a method you should be able to use to update the Android references to the R class, compare my TopActivity class with the original TopActivity class and you'll see where i've used the new Helper method.
I also started to work through the SdkDemoActivity class making some changes but my time is limited and i need to get some other things done today.

Martin.
 

Attachments

  • giuseppe909090_test_eclipse_project.zip
    18.7 KB · Views: 332

giuseppe909090

Member
Licensed User
Longtime User
Hello Martin
wanted to thank you.
I have not tried the code, the message is closed because bees do not have the softwere sygic fleet.
right now I'm on vacation.
I will tell you THANK YOU SO MUCH MORE
Giuseppe
 
Top