Guest User

NewMain

a guest
Jan 29th, 2013
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.29 KB | None | 0 0
  1. /*
  2. * Copyright (C) 2009 The Android Open Source Project
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package com.example.hellojni;
  17.  
  18. import android.app.Activity;
  19. import android.widget.TextView;
  20. import android.os.Bundle;
  21.  
  22. public class HelloJni extends Activity
  23. {
  24. /** Called when the activity is first created. */
  25. @Override
  26. public void onCreate(Bundle savedInstanceState)
  27. {
  28. super.onCreate(savedInstanceState);
  29.  
  30. /* Create a TextView and set its content.
  31. * the text is retrieved by calling a native
  32. * function.
  33. */
  34. TextView tv = new TextView(this);
  35. tv.setText( stringFromJNI() );
  36. setContentView(tv);
  37. }
  38.  
  39. /* A native method that is implemented by the
  40. * 'hello-jni' native library, which is packaged
  41. * with this application.
  42. */
  43.  
  44. static public int add(int a, int b) {
  45. return a+b;
  46. }
  47.  
  48. public native String stringFromJNI();
  49.  
  50. /* This is another native method declaration that is *not*
  51. * implemented by 'hello-jni'. This is simply to show that
  52. * you can declare as many native methods in your Java code
  53. * as you want, their implementation is searched in the
  54. * currently loaded native libraries only the first time
  55. * you call them.
  56. *
  57. * Trying to call this function will result in a
  58. * java.lang.UnsatisfiedLinkError exception !
  59. */
  60. public native String unimplementedStringFromJNI();
  61.  
  62. /* this is used to load the 'hello-jni' library on application
  63. * startup. The library has already been unpacked into
  64. * /data/data/com.example.hellojni/lib/libhello-jni.so at
  65. * installation time by the package manager.
  66. */
  67. static {
  68. System.loadLibrary("hello-jni");
  69. }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment