【问题标题】:Activity doesn't start in ICS , App works perfectly on Motorola Milestone(2.1)活动未在 ICS 中启动,应用程序在 Motorola Milestone(2.1) 上完美运行
【发布时间】:2013-07-10 06:14:24
【问题描述】:

我正在制作一个显示已安装应用程序列表的应用程序,并在项目上单击显示权限。此外,它在后台运行并在设备启动时启动。它在 Motorola Milestone(Android 2.1) 上完美运行,但在 Sony Xperia(ICS) 上测试时,列表不会被点击,因此不会显示显示权限的活动。

LogCat 在错误模式下不显示任何内容。

主活动

package com.example.appslist;

import java.util.List;
import com.example.appslist.adapter.ApkAdapter;
import com.example.appslist.app.AppData;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import com.example.backgroundapp.BackgroundService;






public class ApkListActivity extends Activity implements OnItemClickListener {

    PackageManager packageManager;
    public static boolean isService = false;





    @Override
    public void onCreate(Bundle savedInstanceState) {


        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        startService(new Intent(ApkListActivity.this,BackgroundService.class));
        Intent startMain = new Intent(Intent.ACTION_MAIN);
        startMain.addCategory(Intent.CATEGORY_HOME);
        startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(startMain);
        isService = true;


        packageManager = getPackageManager();
        List<PackageInfo> packageList = packageManager
                .getInstalledPackages(PackageManager.GET_PERMISSIONS);

        ListView mylistview= (ListView) findViewById(android.R.id.list);
        mylistview.setAdapter(new ApkAdapter(this, packageList, packageManager));
        mylistview.setOnItemClickListener(this);
        }





    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position,
            long row) {
        super.onResume();
        stopService(new Intent(ApkListActivity.this,
                BackgroundService.class));

        PackageInfo packageInfo = (PackageInfo) parent
                .getItemAtPosition(position);
        AppData appData = (AppData) getApplication();
        appData.setPackageInfo(packageInfo);

        Intent appInfo = new Intent(ApkListActivity.this, ApkInfo.class);
        startActivity(appInfo);
    }
}

清单

  <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.appslist"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="17" />

   <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />



    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" 
    android:name=".app.AppData">

        <activity
            android:name="com.example.appslist.ApkListActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name=".ApkInfo"
            android:label="@string/title_activity_apk_info" >
        </activity>

      <service android:enabled="true" android:name=".BackgroundService" />

      <receiver 
          android:enabled="true" 
          android:name="com.example.appslist.BootUpReceiver"
        >

        <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED" />
                <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
``</receiver>







</application>


    </manifest>

请帮忙

【问题讨论】:

    标签: android performance


    【解决方案1】:

    你还有这个问题吗?如果是这样,您是否尝试在其他 Android 4.X+ 设备上运行以查看它是否有效?如果这是 Xperia 特定的问题,请告诉我,我可以帮助进一步深入研究。此外,如果它是 Xperia 特定的,您正在测试哪种设备型号?

    【讨论】:

      【解决方案2】:

      PackageInfo 实现 Parcelable 为什么不将其作为额外的意图传递给您的 ApkInfo 活动,而不是扩展 Application 类以存储该数据的奇怪实现。

      另外,我不明白你在这里做什么,在你onCreate 中启动一个服务和一个主要活动,然后单击停止该服务:

      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.main);
          startService(new Intent(ApkListActivity.this,BackgroundService.class));
          Intent startMain = new Intent(Intent.ACTION_MAIN);
          startMain.addCategory(Intent.CATEGORY_HOME);
          startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
          startActivity(startMain);
          isService = true;
      ...
      

      【讨论】:

      • 该服务用于在后台运行应用程序。我的 AppData 类用于获取权限。我不明白为什么它在 ICS 上不能按预期工作,你能建议改变吗?
      • @Prax 我不知道您所说的“在后台运行应用程序”是什么意思,或者您为什么要在另一个活动的onCreate 中启动一个活动。试试我上面说的,在 oncreate 中删除服务和活动的启动,并将PackageInfo 作为意图额外发送,然后发布带有错误的编辑代码。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-03
      • 2021-07-27
      相关资源
      最近更新 更多