Okhelp.cz

Recepty, články, nápady, programování. Dříve dum-zahrada, finance, internet a know-how.okhelp.cz Pro lepší výsledky hledání používejte i diakritiku.

android.app.Application cannot be cast to android.app.Activity



If you using Context as parameter of function try this solution:

public class MyActivity extends Activity {
// bla bla bla .......
//error 
myFc( getapplicationcontext());
// OK
myFc(MyActivity.this);

397LW NO topic_id



Další témata ....(Topics)


120

Statistics usability of mobile phones with Android – October 2011 | statistics-usability-of-mobile-phones-with-android-%e2%80%93-october-2011


Table of usability phones with Android: (Our software)












October 2011 September 2011












Samsung Galaxy S2 10,90%
Samsung Galaxy S 8,10%
Samsung Galaxy Tab 7,00%
Samsung Galaxy Mini 6,20%
HTC Desire HD 4,10%
Samsung Galaxy Ace 4,10%
Samsung Galaxy S 4,00%
Samsung Galaxy Fit 3,30%
HTC Wildfire 3,20%
SEMC Xperia X10 2,20%

























Samsung Galaxy S213.8%
Samsung Galaxy S8.5%
Samsung Galaxy Tab7.4%
Samsung Galaxy Mini5.4%
Samsung Galaxy S4.0%
HTC Desire HD3.8%
Samsung Galaxy Ace3.8%
HTC Wildfire3.2%
Samsung Galaxy Fit3.1%
SEMC Xperia X102.1%



Graph of usability Smartphone with Android - October 2011:
phones-usability-wiht-android-october-2011


Samsung Galaxy S2 vs iPhone4 - video


Samsung Galaxy S2 vs iPhone4 - browsing, gaming, apps, performance, browser, fast, against, navigation, Sygic, apk, Android, iOS


154

Create own custom Title Bar TitleBar with a Icon Android example | create-own-custom-title-titlebar-android-example


onCreate in MainActivity.java

    @Override
	protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
        setContentView(R.layout.main.xml);
        getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.custom_title);
}


You can add to titlebar different Views by xml file.
custom_title.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="//schemas.android.com/apk/res/android" android:id="@+id/screen"
    android:layout_width="fill_parent" android:layout_height="fill_parent"
    android:orientation="vertical">
    <TextView android:id="@+id/left_text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:text="Some text" />

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_alignParentRight="true"
       
        android:src="@drawable/ic_launcher" />
    
</RelativeLayout>





custom-title-titlebar-android
130

Bitmap get Bitmap from resource Android example | bitmap-get-bitmap-from-resource-android-example


PNG, GIF, BMP, JPG

// //www.apache.org/licenses/LICENSE-2.0

// 1.)  Bitmap from stream
            InputStream is = context.getResources().openRawResource(R.drawable.my_image);
            mBitmap = BitmapFactory.decodeStream(is);
           

// 2.) 
            Bitmap ball = BitmapFactory.decodeResource(getResources(), R.drawable.ball);
            int dstWidth =120;
            int dstHeight = 120;
            mBitmap = Bitmap.createScaledBitmap(ball, dstWidth, dstHeight, true);

// 3.)
Bitmap  mBitmap = Bitmap.createBitmap(320, 480, Bitmap.Config.ARGB_8888);


        Bitmap  mBitmap;
        Canvas  mCanvas;
        Paint   mBitmapPaint;
            
            mBitmap = Bitmap.createBitmap(320, 480, Bitmap.Config.ARGB_8888);
            mCanvas = new Canvas(mBitmap);
            mBitmapPaint = new Paint(Paint.DITHER_FLAG);

// 4.)
          Bitmap  mBitmap = Bitmap.createBitmap(w, h, Bitmap.Config.RGB_565);
          Canvas  mCanvas.setBitmap(mBitmap);
            mCanvas.drawColor(0xFFFFFFFF);

31

Start Activity from ListView item click Android example | start-activity-from-listview-item-click-android-example


How start certain Activity if user clicked to ListView item
Start Activity from list – launches other activities from list - latest variant!!!!


public class Main extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        try {
        setContentView(R.layout.main);
        
			ListView mlistView = (ListView) findViewById(R.id.idListView);
			mlistView.setAdapter(new ArrayAdapter<String>(this,
			        android.R.layout.simple_list_item_1, 
			        new String[] {"Game", "Help", "Home site"}));
    
        mlistView.setOnItemClickListener(new OnItemClickListener() {
            public void onItemClick(AdapterView<?> parent, View view,
                int position, long id) {
              // When clicked, show a toast with the TextView text Game, Help, Home
              Toast.makeText(getApplicationContext(), ((TextView) view).getText(),
                  Toast.LENGTH_SHORT).show();
              String sText = ((TextView) view).getText().toString();
              Intent intent = null;
              if(sText.equals("Game"))
              intent = new Intent(getBaseContext(),
						Game.class);
              //else if(sText.equals("Help")) ..........

              if(intent != null)
				startActivity(intent);              
            }
          });
        } catch (Exception e) {
        	// TODO Auto-generated catch block
        	e.printStackTrace();
        }
    
    }
}



Game class Game.java game.xml
You have to add class Game to AndroidManifest.xml

        <activity android:name=".Game" android:label="GameLabel">
        </activity>





package cz.okhelp.listview;

import android.app.Activity;
import android.os.Bundle;

public class Game extends Activity{
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        // you have to create game.xml 
        setContentView(R.layout.game);
    }
}




307

How to set different locales in android | how-to-set-different-locales-in-android


- create new folder with values in resources folder in project with extension your language code
For example:
My language is Czech (cs)
I have to create the folder values-cs in res folder

// for locale English is default
/MyProject/res/values 
<?xml version="1.0" encoding="utf-8"?>
<resources>

    <string name="app_name">App English default</string>
    <string name="action_settings">Settings English default</string>
    <string name="hello_world">Hello world</string>

</resources>

// for locale Czech (cs)
/MyProject/res/values-cs
<?xml version="1.0" encoding="utf-8"?>
<resources>

    <string name="app_name">Aplikace česky cs</string>
    <string name="action_settings">Nastavení česky</string>
    <string name="hello_world">Ahoj světe!</string>

</resources>

// for locale English US (r is region)
/MyProject/res/values-en-rUS

<?xml version="1.0" encoding="utf-8"?>
<resources>

    <string name="app_name">App English Us locale</string>
    <string name="action_settings">Settings English Us locale</string>
    <string name="hello_world">Hello world from USA :)</string>

</resources>


Into every values folder put strings.xml file
Translate every string from values folder into your locale.
If user selected your locale in device settings, application selects a string from the correct (proper) folder.


Editace Jana Žákovská : 2015-11-28 18:55:09
Počet článků v kategorii: 397
Url:android-app-application-cannot-be-cast-to-android-app-activity
Share
Share
Tweet