目前我有一个TabHost实现了3个选项卡,每个选项卡包含一个单独的活动.我的问题是如何在选项卡主机内的一个活动中切换选项卡.我到处寻找并找不到这个问题的真正答案是不成功的.
我有一点时间通过Intent/ Bundles 搞清楚我的方法会有什么数据.我已经尝试添加断点来检查数据,但我没有看到任何东西.也许是因为Parcelable我无法在Eclipse中手动读取它.
例如,a onActivityResult(int requestCode, int resultCode, Intent data)表示a Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI).我如何知道可用的数据?请注意,我不是要求提供哪些数据,但我是如何理解的,所以我可以将相同的想法应用于任何Bundle/ Intent来自Android框架?也许这看起来像文档一样简单,但我没有看到完整的数据列表,我在Eclipse中看不到它.所以我迷路了.
我已经有这个问题差不多2个月了,无法解决这个问题.问题是如果我的应用程序正在运行并且我从Eclipse运行(重新安装)我的应用程序,我会收到一条错误消息,指出我的应用程序崩溃了"不幸的是,已经停止了.".我注意到当我从PC/Eclipse运行它时也会发生这种情况,我认为只有在我暂时不运行它之后才会发生这种情况.
只有当应用程序在第3个activity(BaseDiagramActivity)中处于活动状态然后我再次从Eclipse运行应用程序时才会发生这种情况.除了3个活动之外,我基本上已经删除了所有应用程序,而且它仍在发生.
我搜索并搜索了这个问题的解决方案,但找不到任何好的答案或适用于我的答案.
它似乎不是硬件或Android版本问题因为我在我的平板电脑(4.0.3)和我的手机(4.0.2,在更新前发生在4.0.1上)运行它.除非当然是冰淇淋夹心虫.
如果需要更多信息,请告诉我.
FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to instantiate application android.app.Application: java.lang.NullPointerException
at android.app.LoadedApk.makeApplication(LoadedApk.java:482)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:3938)
at android.app.ActivityThread.access$1300(ActivityThread.java:123)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1185)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4424)
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:784)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at android.app.LoadedApk.initializeJavaContextClassLoader(LoadedApk.java:362)
at android.app.LoadedApk.getClassLoader(LoadedApk.java:305)
at android.app.LoadedApk.makeApplication(LoadedApk.java:474)
... 11 more
Run Code Online (Sandbox Code Playgroud)
LoadedApk.initializeJavaContextClassLoader() - 362行似乎是罪犯
以下是相关文件:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="[my package]"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="14" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" …Run Code Online (Sandbox Code Playgroud) eclipse android android-intent android-4.0-ice-cream-sandwich
我正在研究一个Android教程,它希望我从另一个项目中导入库.导入工作正常,项目正常工作.但是我注意到,这样做会搞砸我的其他几个项目(那些使用Android 2.1的项目),显然是搞乱了构建路径.现在,而不是在gen我看到的文件夹下看到"Google API [Android 2.1]" "Unable to get system library for project".
我验证了以下内容:
我右键单击了该项目并转到Properties我看到正确的项目构建目标被选中(Google API [Android 2.1]),但"无法获取项目的系统库"仍然显示在assets文件夹上方和gen和Android下方依赖.清理所有项目没有帮助.
我该如何解决这个问题?有没有办法在全球范围内解决这个问题,还是我必须逐个解决这个问题?
以下用于设置自定义字体的代码会降低整个应用程序的速度.我如何修改它以避免内存泄漏,提高速度和管理内存?
public class FontTextView extends TextView {
private static final String TAG = "FontTextView";
public FontTextView(Context context) {
super(context);
}
public FontTextView(Context context, AttributeSet attrs) {
super(context, attrs);
setCustomFont(context, attrs);
}
public FontTextView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
setCustomFont(context, attrs);
}
private void setCustomFont(Context ctx, AttributeSet attrs) {
TypedArray a = ctx.obtainStyledAttributes(attrs, R.styleable.FontTextView);
String customFont = a.getString(R.styleable.FontTextView_customFont);
setCustomFont(ctx, customFont);
a.recycle();
}
public boolean setCustomFont(Context ctx, String asset) {
Typeface tf = null;
try {
tf = …Run Code Online (Sandbox Code Playgroud) android android-emulator android-intent android-layout android-listview
好.我正在通过我的应用发送短信.发送文本消息后,它会向服务器发送状态更新.这部分工作正常,但我遇到的问题是双重的.我不确定它们是否相关,但我认为它们是相关的.
我的应用程序可以向多个用户发送单个文本.这是代码示例...
if(phoneNumbers.length > 0 && message.getText().toString().equals("") == false)
{
for(int i=0;i<phoneNumbers.length;i++)
{
sms = SmsManager.getDefault();
try
{
sms.sendTextMessage(phoneNumbers[i], null, message.getText().toString(), null, null);
sentQuantity++;
}
catch(IllegalArgumentException e)
{
}
}
}
Run Code Online (Sandbox Code Playgroud)
基本上,它只是循环遍历一组电话号码,并一次发送一个文本.这是我的问题的一部分.如果我选择3个或更多数字来发送文本,有时并不是所有文本都会被发送.它发生得非常随机.
我认为这是因为发送每条消息之间存在延迟,但代码不会等待足够长的时间.我达到了这个假设,因为如果我使用eclipse进入程序并手动浏览应用程序,一切都可以正常工作.
我的另一个问题是当我将文本消息状态更新发送到Web服务器时.
文本消息发送后,应用程序立即连接到互联网,并通过http发布服务器告知服务器发送的文本数量.这是我的互联网代码片段......
for(int i = 0; i < postNames.length; i++)
{
nameValuePairs.add(new BasicNameValuePair(postNames[i], postValues[i]));
}
//http post
try{
HttpParams httpParameters = new BasicHttpParams();
int timeoutConnection = 10000;
HttpConnectionParams.setConnectionTimeout(httpParameters,timeoutConnection );
HttpClient httpclient = new DefaultHttpClient(httpParameters);
HttpPost httppost = new HttpPost(webAddress);
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity …Run Code Online (Sandbox Code Playgroud) 我正在疯狂地弄清楚处理屏幕旋转的最佳方法是什么.我在这里阅读了数百个问题/答案,但我真的很困惑.
如何在重新创建活动之前保存myClass数据,这样我可以保留所有内容以重绘活动而无需另外无用的初始化?
有没有比parcelable更清洁,更好的方法?
我需要处理旋转,因为我想在横向模式下更改布局.
public class MtgoLifecounterActivity extends Activity {
MyClass myClass;
// Called when the activity is first created
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
If ( ?? first run...myClass == null ? ) {
myClass = new MyClass();
} else {
// do other stuff but I need myClass istance with all values.
}
// I want that this is called only first time.
// then in case of rotation of screen, i want to restore …Run Code Online (Sandbox Code Playgroud) 我正在使用IntentService通过JSON处理与服务器的网络通信.JSON /服务器部分工作正常,但我无法将结果返回到需要的地方.以下代码显示了我如何从onClick()内部启动intent服务,然后让服务更新一个全局变量以将结果传递回主活动.
public class GXActivity extends Activity {
private static final String TAG = "GXActivity";
@Override
public void onCreate(Bundle savedInstanceState) {
// === called when the activity is first created
Log.i(TAG, "GXActivity Created");
super.onCreate(savedInstanceState);
setContentView(R.layout.start);
View.OnClickListener handler = new View.OnClickListener() {
public void onClick(View v) {
// === set up an application context to hold a global variable
// === called user, to contain results from the intent service
GXApp appState = ((GXApp) getApplicationContext());
User user = new User(-1); // …Run Code Online (Sandbox Code Playgroud) 我正在开发一个社交网络应用程序,我们的用户可以将他们的Instagram帐户连接到我们的服务.我想直接在他们的官方Android应用程序中打开Instagram个人资料(如果已安装),但我找不到任何方法可以做到这一点.但是,他们的开发者网站上有一个关于iOS上完全相同功能的页面,但这似乎根本不适用于Android.我在网上找到的所有内容都只提供了在浏览器中打开链接的各种方法.有什么建议?
我的应用程序创建带附件的邮件,并使用意图Intent.ACTION_SEND来启动邮件应用程序.
它适用于我测试过的所有邮件应用,除了新的Gmail 5.0(适用于Gmail 4.9),邮件打开时没有附件,显示错误:"附件权限被拒绝".
在logcat上没有来自Gmail的有用消息.我只测试了Android KitKat上的Gmail 5.0,但是在多个设备上.
我为附件创建了这样的文件:
String fileName = "file-name_something_like_this";
FileOutputStream output = context.openFileOutput(
fileName, Context.MODE_WORLD_READABLE);
// Write data to output...
output.close();
File fileToSend = new File(context.getFilesDir(), fileName);
Run Code Online (Sandbox Code Playgroud)
我知道安全问题MODE_WORLD_READABLE.
我发送这样的意图:
public static void compose(
Context context,
String address,
String subject,
String body,
File attachment) {
Intent emailIntent = new Intent(Intent.ACTION_SEND);
emailIntent.setType("message/rfc822");
emailIntent.putExtra(
Intent.EXTRA_EMAIL, new String[] { address });
emailIntent.putExtra(Intent.EXTRA_SUBJECT, subject);
emailIntent.putExtra(Intent.EXTRA_TEXT, body);
emailIntent.putExtra(
Intent.EXTRA_STREAM,
Uri.fromFile(attachment));
Intent chooser = Intent.createChooser(
emailIntent,
context.getString(R.string.send_mail_chooser));
context.startActivity(chooser);
}
Run Code Online (Sandbox Code Playgroud)
在创建文件或发送意图时,我有什么问题吗?有没有更好的方法来启动带附件的邮件应用程序?或者 …
android ×10
android-intent ×10
eclipse ×2
android-4.0-ice-cream-sandwich ×1
bundle ×1
instagram ×1
sms ×1
tabs ×1